-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (50 loc) · 1.75 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
/* eslint-disable no-console */
'use strict';
const asyncBackground = require('./dr-axel/cps/asynchronous-programming-background');
const arr = [1, 2, 3, 4, 5, 6];
const tree = [[1, 2], 3, [4, 5], 6];
asyncBackground.logArray.syncLoop(arr);
asyncBackground.logArray.syncLoopRecursion(arr);
asyncBackground.logArray.asyncCPSLoop(arr);
// Mapping an array
asyncBackground.mapArray.asyncCPSNonDestructive(
['one', 'two', 'three'], // arrayLike
// declare visitor with calling callback
(elem, index, callback) => callback(elem.toUpperCase()), // visitor
// declare done
result => console.log(`RESULT: ${result}`) // done
);
asyncBackground.mapArray.asyncCPSDestructive(
['one', 'two', 'three'], // arrayLike
// declare visitor with calling callback
(elem, index, callback) => callback(elem.toUpperCase()), // visitor
// declare done
result => console.log(`RESULT: ${result}`) // done
);
asyncBackground.mapArray.asyncCPSDestructiveParallel(
['one', 'two', 'three'], // arrayLike
// declare visitor with calling callback
(elem, index, callback) => callback(elem.toUpperCase()), // visitor
// declare done
result => console.log(`RESULT: ${result}`) // done
);
// Iterating over a tree
asyncBackground.visitTree.sync(tree, value => console.log(value));
asyncBackground.visitTree.asyncCPS(
tree, // tree
// visitor declaration
(value, next) => { // next is a callback wich calls to init next iteration
console.log(value);
next();
},
() => console.log('### Done') // done declaration
);
asyncBackground.visitTree.asyncCPSWithHelpers(
tree, // tree
// visitor declaration
(value, next) => { // next is a callback wich calls to init next iteration
console.log(value);
next();
},
() => console.log('### Done') // done declaration
);