Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rafaelrinaldi/hold-up
:raised_hand: Wait until a given condition is true
https://github.com/rafaelrinaldi/hold-up
Last synced: 15 days ago
JSON representation
:raised_hand: Wait until a given condition is true
- Host: GitHub
- URL: https://github.com/rafaelrinaldi/hold-up
- Owner: rafaelrinaldi
- License: mit
- Created: 2018-07-28T17:28:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:36:44.000Z (almost 2 years ago)
- Last Synced: 2024-10-26T23:07:06.827Z (18 days ago)
- Language: JavaScript
- Homepage:
- Size: 994 KB
- Stars: 22
- Watchers: 3
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hold-up [![Build Status](https://semaphoreci.com/api/v1/rafaelrinaldi/hold-up/branches/master/badge.svg)](https://semaphoreci.com/rafaelrinaldi/hold-up)
> Wait until a given condition is true
## Install
```sh
npm install @rafaelrinaldi/hold-up
```## Usage
```js
import holdUp from '@rafaelrinaldi/hold-up'async function injectVendorScript() {
// Asynchronously load a cheesy vendor script that triggers a bunch of other
// subsequent requests
const script = document.createElement('script')
script.setAttribute('src', 'https://cdn.vendor.com/bundle.min.js')
document.body.appendChild(script)// In order to use their SDK you must wait for the instances to be available
await holdUp(() => window.$vendor && window.$vendor.sdk)// Finally use the SDK
window.$vendor.sdk.show()
}injectVendorScript()
```## API
### `holdUp(condition, [timeoutInterval], [retryInterval])`
Returns a `Promise` instance that resolves whenever `condition` returns `true`. Rejects if `condition` is `false` or `timeoutInterval` times out.
#### `condition`
Type: `Function`
Function that the library will attempt to run until it gets a `true` value back.
#### `timeoutInterval`
Type: `Number`
Default: `8000`The maximum amount of time to wait until execution times out.
#### `retryInterval`
Type: `Number`
Default: `50`The interval between each attempt of calling `condition`.
## License
MIT © [Rafael Rinaldi](rinaldi.io)
---