root / HServer / 00.Server / 00.Program / node_modules / pend / README.md
이력 | 보기 | 이력해설 | 다운로드 (973 Bytes)
| 1 | 39 | HKM | # Pend |
|---|---|---|---|
| 2 | |||
| 3 | Dead-simple optimistic async helper. |
||
| 4 | |||
| 5 | ## Usage |
||
| 6 | |||
| 7 | ```js |
||
| 8 | var Pend = require('pend');
|
||
| 9 | var pend = new Pend(); |
||
| 10 | pend.max = 10; // defaults to Infinity |
||
| 11 | setTimeout(pend.hold(), 1000); // pend.wait will have to wait for this hold to finish |
||
| 12 | pend.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 | }); |
||
| 19 | pend.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 | }); |
||
| 26 | pend.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 | |||
| 32 | Output: |
||
| 33 | |||
| 34 | ``` |
||
| 35 | this function is immediately executed |
||
| 36 | this function is also immediately executed |
||
| 37 | calling cb 1 |
||
| 38 | calling cb 2 |
||
| 39 | this is excuted when the first 2 have returned. |
||
| 40 | err is a possible error in the standard callback style. |
||
| 41 | ``` |