BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / pend / README.md

README.md

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
README.md 973 B Download Raw

Pend

Dead-simple optimistic async helper.

Usage

var Pend = require('pend');
var pend = new Pend();
pend.max = 10; // defaults to Infinity
setTimeout(pend.hold(), 1000); // pend.wait will have to wait for this hold to finish
pend.go(function(cb) {
  console.log("this function is immediately executed");
  setTimeout(function() {
    console.log("calling cb 1");
    cb();
  }, 500);
});
pend.go(function(cb) {
  console.log("this function is also immediately executed");
  setTimeout(function() {
    console.log("calling cb 2");
    cb();
  }, 1000);
});
pend.wait(function(err) {
  console.log("this is excuted when the first 2 have returned.");
  console.log("err is a possible error in the standard callback style.");
});

Output:

this function is immediately executed
this function is also immediately executed
calling cb 1
calling cb 2
this is excuted when the first 2 have returned.
err is a possible error in the standard callback style.
Source
1# Pend
2
3Dead-simple optimistic async helper.
4
5## Usage
6
7```js
8var Pend = require('pend');
9var pend = new Pend();
10pend.max = 10; // defaults to Infinity
11setTimeout(pend.hold(), 1000); // pend.wait will have to wait for this hold to finish
12pend.go(function(cb) {
13 console.log("this function is immediately executed");
14 setTimeout(function() {
15 console.log("calling cb 1");
16 cb();
17 }, 500);
18});
19pend.go(function(cb) {
20 console.log("this function is also immediately executed");
21 setTimeout(function() {
22 console.log("calling cb 2");
23 cb();
24 }, 1000);
25});
26pend.wait(function(err) {
27 console.log("this is excuted when the first 2 have returned.");
28 console.log("err is a possible error in the standard callback style.");
29});
30```
31
32Output:
33
34```
35this function is immediately executed
36this function is also immediately executed
37calling cb 1
38calling cb 2
39this is excuted when the first 2 have returned.
40err is a possible error in the standard callback style.
41```