Socket
Book a DemoInstallSign in
Socket

co-waiter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-waiter

lightweight promise-based wait/setTimeout interface (designed for use with co)

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

co-waiter

Super-simple wait() function which is a lightweight wrapper around setTimeout. I wrote this module just so I'd have an easy way to use things like yield wait.seconds(30); in my co-based workflows.

Provides the following methods. Each waits an amount of time, then resolves a promise. If the v argument is passed, the promise will resolve with that value.

  • wait(n,v) -- milliseconds
  • wait.until(date, v) -- wait until date, then resolve. if date is in the past, resolve immediately.
  • wait.seconds(n,v)
  • wait.second(n,v)
  • wait.sec(n,v)
  • wait.minutes(n,v)
  • wait.minute(n,v)
  • wait.min(n,v)
  • wait.hours(n,v)
  • wait.hour(n,v)
  • wait.days(n,v)
  • wait.day(n,v)
  • wait.weeks(n,v)
  • wait.week(n,v)
  • wait.months(n,v)
  • wait.month(n,v)

install

npm install --save co-waiter

quick examples:

var wait = require('co-waiter');

var delayed = wait.minutes(30, "something");
delayed.then(function(value) {
  console.log("this is", value, "30 minutes too late :(");
});
co(function*() {
  var val = yield wait.sec(3.5, 7);
  return val;
}).then(function(value) {
  console.log(value + "after 3.5 seconds");
});
somePromise.then(function(val) {
  return wait.until(someDate, val);
}).then(function(x) {
  console.log(x, "took a long time to get here!");
});
co(function*() {
  var val = yield someAsyncCall();
  val = yield wait.minute(Math.PI, val);
  return val;
}).then(function(myVal) {
  console.log(myVal + " after π seconds");
});

Share & Enjoy

Keywords

co

FAQs

Package last updated on 24 May 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.