-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
33 lines (28 loc) · 805 Bytes
/
example.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
'use strict';
const resolve = require('.');
const delay = (value, ms = 0) => new Promise(res => setTimeout(() => res(value), ms));
const nested = {
name: delay('nested', 100),
type: delay('choice', 100),
value: delay({ a: () => delay({ one: 'two' }, 25) }, 100),
async choices() {
return delay([delay(() => 'foo', 100), 'bar', 'baz'], 10);
}
};
const obj = async () => ({
name: delay('example', 100),
type: delay('prompt', 100),
value: delay({ a: () => delay({ one: 'two' }, 500) }, 100),
async choices() {
return delay([delay(() => 'foo', 100), 'bar', 'baz', nested], 1000);
}
});
const start = Date.now();
resolve(obj)
.then(res => {
console.log(res);
console.log(res.choices[3]);
})
.then(() => {
console.log('Done', `${Date.now() - start}ms`);
});