Skip to content

kerwal/tasks-each

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tasks-each
----------
tasks-each is a simple function for calling one or many functions, sequentially, for one or many items.
currently relies on the module 'async', but not for long.

installation
------------
npm i kerwal/tasks-each

usage
-----
const tasks_each = require("tasks-each");
const {EventEmitter} = require("events");

const items = ["Elephant", "Donkey", "Moose"];

function task1(item, next) {
    next("result 1");
    // pass an Error object to next() to cause the string of tasks to cancel
}

function task2(item, next) {
    next("result 2");
}

var emitter = new EventEmitter();
emitter.on('task starting', (device, task) => {
    // ...
});

emitter.on('item finished', (device, results) => {
    // ...
    // results expected: [["result 1", "result 2"], ["result 1", "result 2"]]
});

tasks_each([task1, task2], items, emitter)
.then(() => {
})
.catch((error) => {

});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published