Socket
Socket
Sign inDemoInstall

now-and-later

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

now-and-later

Map over an array or object of values in parallel or series, passing each through the async iterator, with optional lifecycle hooks.


Version published
Weekly downloads
1.9M
decreased by-1.25%
Maintainers
2
Weekly downloads
 
Created

What is now-and-later?

The now-and-later npm package is designed to execute functions in a specific order, allowing for both series and parallel execution with support for mapping and iterating over collections. It provides a way to manage and coordinate asynchronous tasks, making it easier to handle complex flows in Node.js applications.

What are now-and-later's main functionalities?

Map Series

Executes an iterator function on each item in an array, in series. Each iterator is called with the item, key, and a callback function. The results are collected and passed to the final callback.

const nal = require('now-and-later');
nal.mapSeries(['a', 'b', 'c'], function(value, key, cb) {
  setTimeout(function() {
    cb(null, value.toUpperCase());
  }, 1000);
}, function(err, results) {
  console.log(results); // ['A', 'B', 'C']
});

Map

Similar to mapSeries, but executes the iterator functions in parallel. The final callback is called once all iterators have completed.

const nal = require('now-and-later');
nal.map(['a', 'b', 'c'], function(value, key, cb) {
  setTimeout(function() {
    cb(null, value.toUpperCase());
  }, 1000);
}, function(err, results) {
  console.log(results); // ['A', 'B', 'C']
});

Map Values

Executes an iterator function on each property of an object, in parallel. The iterator is called with the value, key, and a callback function. The results are collected into an object and passed to the final callback.

const nal = require('now-and-later');
const obj = { a: 1, b: 2, c: 3 };
nal.mapValues(obj, function(value, key, cb) {
  setTimeout(function() {
    cb(null, value * 2);
  }, 1000);
}, function(err, results) {
  console.log(results); // { a: 2, b: 4, c: 6 }
});

Map Values Series

Works like mapValues but executes the iterator functions in series.

const nal = require('now-and-later');
const obj = { a: 1, b: 2, c: 3 };
nal.mapValuesSeries(obj, function(value, key, cb) {
  setTimeout(function() {
    cb(null, value * 2);
  }, 1000);
}, function(err, results) {
  console.log(results); // { a: 2, b: 4, c: 6 }
});

Other packages similar to now-and-later

Keywords

FAQs

Package last updated on 25 Jun 2022

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