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

wait-then

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wait-then

Utility function that returns a promise that resolves after x ms

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by66.67%
Maintainers
1
Weekly downloads
 
Created
Source

wait-then

GitHub version NPM Version Coverage Status

Deps Dev Deps Peer Deps

NPM Downloads GitHub stars GitHub forks GitHub issues

Utility function that returns a promise that resolves after x ms

Can be used as a yieldable with co or in koa.

Basic example:

var wait = require('wait-then'),
    timeout = wait.timeout;

wait(2000).then(function() {
    console.log('This is logged after 2 seconds');
});

timeout(2000).catch(e) {
    console.log('This is logged after 2 seconds');
}

Example with co:

var wait = require('wait-then'),
    timeout = wait.timeout,
    co = require('co');

co(function *() {
    yield wait(1000);
    console.log('This is logged after 1 second');
});

co(function *() {
    try {
        yield timeout(1000);
    } catch (e) {
        console.log('This is logged after 1 second');
    }
});

The generator function passed into co can be yielded in a middleware in koa.

Note: This relies on the existence of a global Promise object as defined in the ECMAScript 6 (Harmony) proposal.

How this differs from co-sleep and co-wait is that both of them use thunks, support for which is set to be deprecated. wait-then instead uses Promises, which are also yieldable.

Keywords

FAQs

Package last updated on 21 Dec 2015

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