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

asink

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asink

Like async/await, but asink/yield.

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by22.22%
Maintainers
1
Weekly downloads
 
Created
Source

asink

Like async/await, but asink/yield. A placeholder until async/await are standardized and included in node.js and web browsers. "asink" is exactly the same thing as "spawn", but with a slightly better name.

How To Use

Without asink, you might write an asynchronous function like this:

function myfunc () {
  return thingThatReturnsAPromise().then(() => {
    // do something else
    return aPromise1
  }).then(() => {
    // do yet another thing
    return aPromise2
  })
}

But with asink, you can write this code like this:

function myfunc () {
  return asink(function * () {
    yield thingThatReturnsAPromise()
    // do something else
    yield aPromise1
    // do yet another thing
    return aPromise2
  })
}

Code written with asink looks nicer and is easier to write and understand than without it. It is especially nice when there is a lot of logic with promises, or when there are errors that go inside try/catch blocks. It is almost the same as the async/await pattern of the upcoming version of javascript, ES7, but works today in node.js and (most modern) web browsers.

The same code written in the as-yet-unworking-and-unstandardized-es7 is:

async function myfunc () {
  await thingThatReturnsAPromise()
  // do something else
  await aPromise1
  // do yet another thing
  return aPromise2
}

asink lets you have most of the readability and writability gains in a form that works today without waiting for ES7. It is also maximally forwards-compatible in the sense that when async/await is actually available, a straightforward conversion of each asink function to the async/await pattern is possible by making each function async, removing the "return asink" line and corresponding closing brace and parenthesis, and making each yield an await.

FAQs

Package last updated on 27 Sep 2016

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