-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathexample.js
72 lines (62 loc) · 1.54 KB
/
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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict'
const avvio = require('..')()
function a (instance, opts, cb) {
(opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })
setTimeout(cb, 10)
}
const pointer = a
function b (instance, opts, cb) {
(opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })
setTimeout(cb, 20)
}
function c (instance, opts, cb) {
(opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })
setTimeout(cb, 30)
}
avvio
.use(first, { hello: 'world' })
.use(duplicate, { count: 0 })
.use(function a (instance, opts, cb) {
instance.use(pointer, { use: [b], subUse: [c] })
.use(b)
setTimeout(cb, 42)
})
.after(function (err, cb) {
if (err) {
console.log('something bad happened')
console.log(err)
}
console.log('after first and second')
cb()
})
.use(duplicate, { count: 4 })
.use(third)
.ready(function (err) {
if (err) {
throw err
}
console.log('application booted!')
})
avvio.on('preReady', () => {
console.log(avvio.prettyPrint())
})
function first (instance, opts, cb) {
console.log('first loaded', opts)
instance.use(second)
setTimeout(cb, 42)
}
function second (instance, opts, cb) {
console.log('second loaded')
process.nextTick(cb)
}
function third (instance, opts, cb) {
console.log('third loaded')
cb()
}
function duplicate (instance, opts, cb) {
console.log('duplicate loaded', opts.count)
if (opts.count > 0) {
instance.use(duplicate, { count: opts.count - 1 })
}
setTimeout(cb, 20)
}