Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/adamsiekierski/holdmabeer

Hold ma BEEER 🍺
https://github.com/adamsiekierski/holdmabeer

hold js node npm promise sleep timeout wait

Last synced: about 1 month ago
JSON representation

Hold ma BEEER 🍺

Awesome Lists containing this project

README

        




Hold ma BEER!


Let your app do something important







`holdmabeer` is a simple package, that lets you create a `Promise`, that resolves after a specific time.

## Installation

```
npm install holdmabeer
```

## Usage

`holdmabeer` exports a `hold` function, which accepts either a number or a string. When given a number, returns a `Promise` that resolves after given number of milliseconds. String can be although in two formats - seconds or milliseconds. For example `420ms` or `69s`

## Examples

**Just a simple promise, which resolves after 100 milliseconds**

```js
import { hold } from 'holdmabeer';

hold(100).then(() => console.log('yummy'));
```

or

```js
import { hold } from 'holdmabeer';

hold('100ms').then(() => console.log('yummy'));
```

**Promise, that resolves after 1 second**

```js
import { hold } from 'holdmabeer';

hold('1s').then(() => console.log('yummy'));
```

**You can also use it inside an asynchronous function**

```js
import { hold } from 'holdmabeer';

(async () => {
await hold('3s');
console.log('noice');
})();
```

Top-level `await` is coming to JavaScript, so in some time it could be used like this:

```js
import { hold } from 'holdmabeer';

await hold('3s');
console.log('noice');
```

## Contributing

- Do a fork of the repo
- `npm install`
- Apply your changes, be sure to use Prettier for code formatting
- Create a pull request
- Well, it merge time, baby

## License

This project is licensed under the MIT License.

## Credits

- [ejer](https://github.com/datejer) - Idea
- [me](https://github.com/AdamSiekierski) - Code

## Shameless plug

I'm an author of [Require Podcast](https://require.podcast.gq) - Polish podcast about webdevelopment! If you're Polish, be sure to check it out!