Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-spin-wait

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-spin-wait

An ES6-Promise based spin wait

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

promise-spin-wait Build Status

An ES6-Promise based spin wait

Install

$ npm install --save promise-spin-wait

Usage

Imagine you'd want to test a script that sends emails. Sadly the infrastructure that actually sends them is out of your controll, so emails are not delivered instantly. This is when a spin wait can be useful, it allows you to check regularly for a certain criteria until it's fulfilled.

const spinner = require('promise-spin-wait');

return sendEmail() // Asyncronous, but it will return before the email has actually been delivered
.then(() => {
    return spinner(
        () => {
            return getEmailInboxCount().then(n => n > 0);
        },
        {
            message: "Timeout: No Email received",
            timeout: 5000,
            interval: 500
        }
    );
})

API

spinner(fn, options)

Returns a promise for a the first truish response of fn() or the first rejected promise of fn();

fn

A function returning a value or a promise. If a promise is returned fn() will not be called again until it is resolved. Any errors thrown or promise rejections will lead to the spinner rejecting as well.

Only a truish return value will lead to the spinner stopping.

options
message

Type: string
Default: Timeout

Message thrown when timeout occurs

timeout

Type: number
Default: 5000

Milliseconds since start when instead of calling fn again an timeout error will be returned

interval

Type: number
Default: 100

Duration between the last time fn() has been fulfilled and the next fn() is being called

License

MIT © marekventur

Keywords

FAQs

Package last updated on 13 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc