New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mybug/awaitor

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mybug/awaitor

awaitable callback

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

@mybug/awaitor

awaitable callback.

async/await way to call callback style functions

deprecated

Ownership of this package has been transferred, please use [@superjs/awaitor](https://www.npmjs .com/package/@superjs/awaitor)

thought

If you want to convert callback style to async/await style, you can either:

  1. wrap the operation to return a promise
  2. just call the operation, using @mybug/awaitor as callback, like the example below

usage

awaitor()

return an awaitable callback, the promiseValue of which is the args array it's called with

awaitor.norm()

same as above, but it only accept two args: (err,value). If err exists, promiseValue will be err and rejected. Otherwise, promiseValue will be value.

example

const awaitor = require('@mybug/awaitor')
// await can't be used without being wrapped by async function
;(async ()=>{
  let cb = awaitor()
  foo(1,2,cb) // whenever a callback is needed, just use cb
  let result = await cb //result is an array, containing the args cb received
  console.log(result) // [3]
})()

function foo(a,b,cb){
  setTimeout(()=>cb(a+b),1000)
}

use together with @mybug/wait

wait can await something synchronously.

const awaitor = require('@mybug/awaitor')
const wait = require('@mybug/wait')

let cb = awaitor()
foo(1,2,cb) // whenever a callback is needed, just use cb
let result = wait(cb) //result is an array, containing the args cb received
console.log(result) // [3]

function foo(a,b,cb){
  setTimeout(()=>cb(a+b),1000)
}

compatibility

You can use @mybug/awaitor in both nodejs and browser environment.

Keywords

FAQs

Package last updated on 06 Jan 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

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