🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

doneable

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doneable

Easily extend a stateful callback based operation into a thenable that can await'ed

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

doneable

Easily extend a stateful callback based operation into a thenable that can await'ed.

npm install doneable

Usage

const Doneable = require('doneable')

class Operation extends Donable {
  constructor (args, callback) {
    super(callback)
    this.destroyed = false

    // do a bunch of stuff
    setImmediate(() => {
      if (this.destroyed) return this.done(new Error('Was aborted'))
      this.done(null, 'value')
    })
  }

  destroy () {
    this.destroyed = true
  }
}

const op = new Operation(..., function (err, val) {
  console.log('Optional callback', err, val)
})

// but you can also await it
console.log(await op) // returns 42

License

MIT

FAQs

Package last updated on 19 Oct 2019

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