Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@joshwillik/task

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@joshwillik/task

async function++

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Installation

npm install @joshwillik/task

Usage

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()
    }
  })
  await this.wait()
  // will always run at the end of the task
  this.finally(() => fs.rmdir(scratch_dir))
  if (Math.round(Math.random())) {
    console.log('success')
  } else {
    throw new Error('failed :(')
  }
}).then(() => {
  console.log('task done')
})

// sleep
task(async function(){
  console.log('before', new Date())
  await task.sleep(1e3)
  console.log('after', new Date())
}).then(() => {
  console.log('task done')
})

Keywords

FAQs

Package last updated on 03 Sep 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc