forked from yortus/asyncawait
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasyncMod.js
More file actions
36 lines (26 loc) · 848 Bytes
/
asyncMod.js
File metadata and controls
36 lines (26 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var fs = require('fs');
var Promise = require('bluebird');
var async = require('..').async;
var await = require('..').await;
var ITER = async.mod({ isIterable: true, acceptsCallback: true, returnValue: 'thunk' });
var someNums = ITER (function (yield_) {
await (Promise.delay(500));
yield_(111);
await (Promise.delay(500));
yield_(222);
await (Promise.delay(500));
yield_(333);
await (Promise.delay(500));
});
var program = async (function() {
var iterator = someNums();
var thunk = iterator.forEach(console.log, function (err) {
console.log('Finished (callback)');
});
thunk(function (err) {
console.log('Finished (thunk)');
});
console.log('Finished (synchronous)');
});
console.log('running...');
program().catch(function (err) { console.log('ERROR: ' + err); });