Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: offer an init event to monitor when repo is there and avoid setT…
Browse files Browse the repository at this point in the history
…imeout
  • Loading branch information
daviddias committed Mar 20, 2017
1 parent 3bd7d98 commit c4130b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ function spawnDaemon (num, callback) {
}
})

setTimeout(() => {
node.on('init', () => {
const daemon = new HTTPAPI(node.repo.path())
nodes.push(daemon)
setTimeout(() => daemon.start(callback), 400)
}, 800)
})
}

gulp.task('libnode:start', (done) => {
Expand Down
10 changes: 9 additions & 1 deletion src/core/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ module.exports = function init (self) {
cb(null, true)
})
}
], callback)
], (err, success) => {
if (err) {
return callback(err)
}

self.emit('init')

callback(null, success)
})
}
}
8 changes: 3 additions & 5 deletions test/core/create-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ describe('create node', () => {
start: false
})

setTimeout(() => {
node.on('init', () => {
node.on('stop', () => done())
node.on('start', () => node.stop())
node.start()
}, 1000)
})
})

it('init: true, start: false, use callback', (done) => {
Expand All @@ -154,9 +154,7 @@ describe('create node', () => {
start: false
})

setTimeout(() => {
node.start(() => node.stop(done))
}, 1000)
node.on('init', () => node.start(() => node.stop(done)))
})

it('overload config', (done) => {
Expand Down

0 comments on commit c4130b9

Please sign in to comment.