Basic usage of avvio for asynchronous bootstrapping
mainAvvio is a graph-based, reentrant asynchronous bootstrapper. It allows you to load plugins or components in a specific order, even when loading plugins from within other plugins. It supports both callback-style and async/await functions.
Key features:
- Reentrancy: You can call
.use()inside a plugin being loaded by avvio. - Graph-based: Ensures correct load order and dependency management.
- Flexible API: Supports callbacks, Promises, and
async/await.
'use strict'
const app = require('avvio')()
app
.use(first, { hello: 'world' })
.after((err, cb) => {
console.log('after first and second')
cb()
})
app.use(third)
app.ready(function (err) {
if (err) {
throw err
}
console.log('application booted!')
})
function first (instance, opts, cb) {
console.log('first loaded', opts)
instance.use(second)
cb()
}
function second (instance, opts, cb) {
console.log('second loaded')
process.nextTick(cb)
}
async function third (instance, opts) {
console.log('third loaded')
}