Skip to content

Commit

Permalink
added an example for passing a result to the success handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Dana Simmons committed Jun 10, 2019
1 parent 0b663a8 commit f844306
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ q.splice(2, 0, function (cb) {
cb()
})

// jobs can send a result to the 'success' event
q.push(function(callback){
asyncJob()
.then(result=>callback(null,result))
.catch(error=>callback(error))
})

q.on('success',function(result,job){
console.log('Result from asyncJob():' result)
})

q.on('error', function(error,job){
console.log('Error from asyncJob():' error)
throw error
})

// use the timeout feature to deal with jobs that
// take too long or forget to execute a callback
q.timeout = 100
Expand Down

0 comments on commit f844306

Please sign in to comment.