New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

asyncflow-gen

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asyncflow-gen

Asynchronous control flow with generators

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

asyncflow

Build Status Coverage Status

Manage IO operations in Node.js using direct style (sync code like) without callbacks. It works with generators under the hood.

How to install:

npm i asyncflow-gen

How to use it:


const asyncFlow = require('asyncflow-gen');

asyncFlow(function* (callback) {

  yield fs.writeFile('./test/testFile', 'Hey there!', callback);
  
  const data = yield fs.readFile('./test/testFile', 'utf8', callback);
            
  console.log('data is: ', data);

  yield fs.unlink('./test/testFile', callback);
            
  console.log('That is all, folks! Where are the callbacks??');
  
});

What we are avoiding:


fs.writeFile('./test/testFile', 'Hey there!', err => {

  if (err) {
    handleErrorFunction(err);
  }
  
  fs.readFile('./test/testFile', 'utf8', (err, data) => {
  
    if (err) {
      handleErrorFunction(err);
    }
    
    console.log('data is: ', data);
    
    fs.unlink('./test/testFile', err => {
    
      if (err) {
        handleErrorFunction(err);
      }
      
      console.log('That is all, folks! Yes, I do not like this callback cascade.');
      
    });
  
  });

});

Keywords

async

FAQs

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