Socket
Book a DemoInstallSign in
Socket

serialize-async

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

serialize-async

Serialize execution of javascript asynchronous functions

latest
Source
npmnpm
Version
1.0.7
Version published
Maintainers
1
Created
Source

serialize-async

Serialize execution of javascript asynchronous functions. Typically those functions have their own async callback where either next(mem) can start the next function, or if error, fail() to abort. The variable "mem" is accessible all the way through

Install

$ npm install --save serialize-async

Usage

const serialize = require('serialize-async');

serialize( {init mem} , [
    function (mem, next, fail) {
      // receive the init mem, and start the first job
      asyncFun1(
        ..., 
        function cb(result){
          mem.result = result // update mem in place ...
          next(mem);          // start the next job
        }
      );
    },
    function (mem, next, fail) {
      // job2 started by the previous next(mem), certainly receive the updated mem
      asyncFun2(
        ..., 
        function cb(err, result){
          if (err) {
            fail(err); // if anything wrong, cancel the rest of jobs
            return;
          }
          ...
          next(mem);   // move on
        }
      );
    },
    ...
]).then((mem)=>{
  // when all job call next(mem), the latest mem get here
  ...
}).catch((err)=>{
  // as long as one fail() call
  ...
}).finally(()=>{
  // Thanks bluebird. Yes, serialize() return bluebird promise
  ...
})

API

serialize(init, [fn1, fn2 ...]): Promise

License

MIT ©

Keywords

serialize

FAQs

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.