Installation
npm install @joshwillik/task
Usage
const task = require('@joshwillik/task')
const fs = require('fs')
const builder = require('./some_fake_module.js')
task(async function() {
let build_job = builder.start()
console.log(`Starting build`)
build_job.on('built', () => this.continue())
await this.wait()
console.log('Build finished')
build_job.on('uploaded', () => this.continue())
await this.wait()
console.log('Upload finished')
build_job.on('verified', content_sum => this.continue(content_sum))
let content_sum = await this.wait()
console.log(`Verified built image: ${content_sum}`)
}).then(() => {
console.log('task done')
})
task(async function(){
let scratch_dir = '/tmp/scratch-dir'
fs.mkdir(scratch_dir, err => {
if (err) {
this.throw(e)
} else {
this.continue()
}
})
await this.wait()
this.finally(() => fs.rmdir(scratch_dir))
if (Math.round(Math.random())) {
console.log('success')
} else {
throw new Error('failed :(')
}
}).then(() => {
console.log('task done')
})
task(async function(){
console.log('before', new Date())
await task.sleep(1e3)
console.log('after', new Date())
}).then(() => {
console.log('task done')
})