JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1234
  • Score
    100M100P100Q95606F
  • License MIT

Asnyc map that actualy works. Parallel and Series

Package Exports

  • foreign

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (foreign) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

foreign

Asnyc map that actualy works. Parallel, Series, Sync and Async

Usage

const foreign = require('foreign');

Parallel

const items = [1, 2, 3];

foreign.parallel(
    (item, callback) => {
        somethingAsync(item, callback);
    },
    items,
    (error, result) => {},
);

Series

const items = [1, 2, 3];

foreign.series(
    (item, callback) => {
        somethingAsync(item, callback);
    },
    items,
    (error, result) => {},
);

SeriesPromise

const items = [1, 2, 3];

const result = foreign.series(async (item) => someAsyncFunction(item), items);

SeriesAll

const items = [1, 2, 3];

foreign.seriesAll(
    (item, callback) => {
        somethingAsync(item, callback);
    },
    items,
    (error, result) => {
        // 'error' will always be a either array or object of errors
        // 'result' will always be a either array or object of results
        // depending on the type `items` is.
        //
        // NOTE: `error.length` is not a reliable indicator of number of errors
        //
        // All items will be processed in order even if
        // some return errors. `foreign.series` and `foreign.seriesPromise` will return
        // on first error

        // example error checking:
        if (error) {
            const itemsThatFailed = Object.keys(error);
        }
    },
);

Multiple return values

const items = [1, 2, 3];

foreign.series(
    (item, callback) => {
        callback(null, item, 'foo');
    },
    items,
    (error, results) => {
        console.log(results); // [[1, 'foo'], [2, 'foo'], [3, 'foo']]
    },
);