A minimal solution to defer application starts
after you have resolved your network or file dependencies.
If you have multiple dependencies like connecting to a database or other initial processing that needs to be done before the application starts, this will come in handy.
npm install headrush
You need to provide the initial dependencies you're expecting , after which the ready event will be emitted. This needs to be provided once only.
Also, you need to call the stun
function once you have finished some specific processing.
var HeadRush = require('headrush')
var headRush = new HeadRush({
deps: [
'intialProcessing',
'redis',
'mongo'
]})
headRush.on('ready', function() {
// call the function to start your app
console.log('ready')
})
function initialProcessing() {
// do some processing here
headRush.stun({
dep: 'intialProcessing'
})
}
function connectToRedis() {
// After connecting to redis
headRush.stun({
dep: 'redis'
})
}
function connectToMongo() {
// After connecting to mongo
headRush.stun({
dep: 'mongo'
})
}
initialProcessing()
connectToMongo()
connectToRedis()
File 1
var HeadRush = require('headrush')
var headRush = new HeadRush({
deps: [
'intialProcessing',
'someMoreProcessing'
]})
function initialProcessing() {
// do some processing here
headRush.stun({
dep: 'intialProcessing'
})
}
File 2
var HeadRush = require('headrush')
var headRush = new HeadRush()
function someMoreProcessing() {
// do some processing here
headRush.stun({
dep: 'someMoreProcessing'
})
}
MIT