-
Notifications
You must be signed in to change notification settings - Fork 0
/
with_galaxy.js
49 lines (42 loc) · 884 Bytes
/
with_galaxy.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
43
44
45
46
47
48
49
var q = require('q');
var galaxy = require('galaxy');
/**
* typical callback
*/
function cb1(msg, cb){
setTimeout(function () {
cb(undefined, msg + '-p1');
}, 1000)
}
/**
* starify typical callback function.
*/
var cbs = galaxy.star(cb1);
/**
* this generator function uses typical starred method cbs.
*/
function* f1(msg) {
if (msg != null)
return yield* cbs(msg + '-f1');
return yield "xxxx";
}
/**
* generator function using another generator function.
*/
function* f2(msg) {
return yield* f1(msg + '-f2')
}
/**
* running generator function using galaxy.main.
* Please note, if you want to return anything from this function, use promise or callback.
*/
function test(msg) {
galaxy.main(function* () {
var a = yield* f1('test' + msg);
console.log('a', a);
var b = yield* f2(a);
console.log('b', b)
})
}
test('1');
test('2');