-
-
Notifications
You must be signed in to change notification settings - Fork 805
/
Copy pathindex.js
47 lines (39 loc) · 843 Bytes
/
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
'use strict';
var randu = require( '@stdlib/math/base/random/randu' );
var ceil = require( '@stdlib/math/base/special/ceil' );
var repeatString = require( '@stdlib/string/repeat' );
var ifthenAsync = require( './../lib' );
var i;
function next() {
ifthenAsync( predicate, x, y, done );
}
function predicate( clbk ) {
setTimeout( onTimeout, 0 );
function onTimeout() {
clbk( null, randu() > 0.9 );
}
}
function x( clbk ) {
setTimeout( onTimeout, 0 );
function onTimeout() {
clbk( null, repeatString( 'BOOP', ceil( randu()*3.0 ) ) );
}
}
function y( clbk ) {
setTimeout( onTimeout, 0 );
function onTimeout() {
clbk( null, repeatString( 'beep', ceil( randu()*5.0 ) ) );
}
}
function done( error, result ) {
if ( error ) {
throw error;
}
i += 1;
console.log( result );
if ( i < 100 ) {
next();
}
}
i = 0;
next();