faithful

Like Async, but employing promises.

Faithful

Like Async, but employing promises.

Faithful mimics the Async API, with three important differences:

  • the functions don't have a callback argument
  • the functions return a Promises/A+ promise (powered by RSVP.js)
  • the iterator is not passed a callback argument. Instead, an iterator is expected to return a promise. If the iterator throws an error or does not return a promise-like object (i.e. it does not have a then method), then the promise returned by the function will fail.

Currently, faithful only implements each, eachSeries, map, and mapSeries.

faithful = require "faithful"
faithful.each(inputsiterator)
  .then ->
    console.log "Everything has executed."
  .then null(error) ->
    console.error error

faithful.eachSeries works the same, but ensures the iterator is not called with the next argument until the promise returned by the previous iterator has resolved.

each and eachSeries are also available as forEach and forEachSeries, respectively.

faithful = require "faithful"
faithful.map(inputsiterator)
  .then (outputs) ->
    console.log outputs
  .then null(error) ->
    console.error error

faithful.mapSeries works the same, but ensures the iterator is not called with the next argument until the promise returned by the previous iterator has resolved.

The initial structure of this module was generated by Jumpstart, using the Jumpstart Black Coffee template.

faithful is released under the MIT License.
Copyright (c) 2013 Meryn Stol