-
Notifications
You must be signed in to change notification settings - Fork 77
/
iteration.js
42 lines (33 loc) · 902 Bytes
/
iteration.js
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
37
38
39
40
41
42
var fs = require('fs');
var Promise = require('bluebird');
var async = require('..').async;
var await = require('..').await;
var someNums = async.iterable (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();
await (iterator.forEach(console.log));
// or the long (but equivalent) way...
//while (true) {
// var item = await (iterator.next());
// if (item.done) break;
// console.log(item.value);
//}
return 'Finished!';
});
console.log('running...');
program()
.then(function (result) {
console.log(result);
})
.catch(function(err) {
console.log('----- rejected: -----');
console.log(err);
});