Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@joshwillik/task
Advanced tools
npm install @joshwillik/task
const task = require('@joshwillik/task')
const fs = require('fs')
const builder = require('./some_fake_module.js')
// wait/continue
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')
})
// finally
task(async function(){
let scratch_dir = '/tmp/scratch-dir'
fs.mkdir(scratch_dir, err => {
if (err) {
this.throw(e)
} else {
this.continue()
}
})
// altertatively, you can do this instead:
// fs.mkdir(scratch_dir, this.continue_cb)
await this.wait()
// will always run at the end of the task, even if something throws
this.finally(() => fs.rmdir(scratch_dir))
// as proven by this code which randomly throws
if (Math.round(Math.random())) {
console.log('success')
} else {
throw new Error('failed :(')
}
}).then(() => {
console.log('task done')
}).catch(err => {
console.log('task failed, but scratch_dir is still gone')
})
// sleep
task(async function(){
console.log('before', new Date())
await task.sleep(1e3)
console.log('after', new Date())
}).then(() => {
console.log('task done')
})
this.wait()
returns a promise that will be resolved when this.continue()
or this.throw()
is called.
this.continue()
resolves a the promise that this.wait()
returns.
this.throw(err)
rejects a the promise that this.wait()
returns.
this.continue_cb
can be used to avoid boilerplate code like the following:
await task(async function() {
fs.readFile('filename.txt', (err, value) => {
if (err) {
this.throw(err)
} else {
this.continue(value)
}
})
let file_data = await this.wait()
console.log('file data', file_data)
})
by replacing it with:
await task(async function() {
fs.readFile('filename.txt', this.continue_cb)
let file_data = await this.wait()
console.log('file data', file_data)
})
A utility function that returns a promise that will resolve after ms
milliseconds.
FAQs
async function++
The npm package @joshwillik/task receives a total of 6 weekly downloads. As such, @joshwillik/task popularity was classified as not popular.
We found that @joshwillik/task demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.