CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
example.js73 linesDownload Raw Back to examples
1'use strict'2 3const avvio = require('..')()4 5function a (instance, opts, cb) {6  (opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })7  setTimeout(cb, 10)8}9const pointer = a10 11function b (instance, opts, cb) {12  (opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })13  setTimeout(cb, 20)14}15 16function c (instance, opts, cb) {17  (opts.use || []).forEach(_ => { instance.use(_, { use: opts.subUse || [] }) })18  setTimeout(cb, 30)19}20 21avvio22  .use(first, { hello: 'world' })23  .use(duplicate, { count: 0 })24  .use(function a (instance, opts, cb) {25    instance.use(pointer, { use: [b], subUse: [c] })26      .use(b)27    setTimeout(cb, 42)28  })29  .after(function (err, cb) {30    if (err) {31      console.log('something bad happened')32      console.log(err)33    }34    console.log('after first and second')35    cb()36  })37  .use(duplicate, { count: 4 })38  .use(third)39  .ready(function (err) {40    if (err) {41      throw err42    }43    console.log('application booted!')44  })45 46avvio.on('preReady', () => {47  console.log(avvio.prettyPrint())48})49 50function first (instance, opts, cb) {51  console.log('first loaded', opts)52  instance.use(second)53  setTimeout(cb, 42)54}55 56function second (instance, opts, cb) {57  console.log('second loaded')58  process.nextTick(cb)59}60 61function third (instance, opts, cb) {62  console.log('third loaded')63  cb()64}65 66function duplicate (instance, opts, cb) {67  console.log('duplicate loaded', opts.count)68  if (opts.count > 0) {69    instance.use(duplicate, { count: opts.count - 1 })70  }71  setTimeout(cb, 20)72}73