0.1.5 • Published 8 years ago

auto-promise v0.1.5

Weekly downloads
374
License
MIT
Repository
github
Last release
8 years ago

auto-promise

Build Status

auto-promise is yet another version of the awesome async.auto, but for promises. In contrast to other implementations it can be used in two modes: Injected and classic. Also, it supports node-style callbacks intermixed.

Installation:

npm install auto-promise

Usage:

let auto = require('auto-promise');
  
auto(tasks).then(results => { ... });

Tasks can be defined in an injected and a "classic" way, and these can be mixed. Task values can be a literal, a function or a function returning a promise, and will behave as expected.

Injected

In the injected way, the parameters of task functions are parsed out and matched to task keys:

auto({
  ...
  taskX: function(taskY) { return taskY; },
  ...
})

This is equivalent to the following definition in classic mode.

Classic

auto({
  ...
  taskX: ['taskY', function(results) { return results.taskY; }]
  ...
})

Mixed example

auto({
  task1: 'Hello',
  task2: task1 => {
    return ' world';
  },
  task3: (task1, task2) => new Promise((resolve, reject) => resolve('!')),
  task4: (task1, task2, task3) => task1 + task2 + task3
}).then(results => {
  console.log(results);
  /* 
    Results are now. { 
      task1: 'Hello',
      task2: ' world',
      task3: '!',
      task4: 'Hello world!'
  */
});
0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago