Giter Club home page Giter Club logo

async-series's Introduction

async-series

Run a series of callbacks in sequence, as simply as possible.

More or less equivalent to async.series - solely for the sake of keeping some modules tiny for browserify.

Installation

npm install async-series

Usage

series(tasks, callback, safe)

Where tasks is an array of functions, each with their own done argument. callback is called when finished. Setting safe to true will ensure there's at least a tick between each task to prevent RangeErrors.

series([
  function(done) {
    console.log('first thing')
    done()
  },
  function(done) {
    console.log('second thing')
    done(new Error('another thing'))
  },
  function(done) {
    // never happens, because "second thing"
    // passed an error to the done() callback
  }
], function(err) {
  console.log(err.message) // "another thing"
})

async-series's People

Contributors

hughsk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

swaibat

async-series's Issues

Bump to v1 to conform to semver

If you're not already familiar with semantic versioning check out http://semver.org/

Since this library is past initial development and has a stable public API, the version should be bumped to 1.0.0

Thanks for this module!

Usage from class instance

I am trying to pass the results of async-series to a promise for later use

class MyClass {
    constructor(preFolder, postFolder, debug) {
        this.result;
    }

    run() {
        series([
            function(done) {
                console.log('first thing')
                done()
            },
            function(done) {
                console.log('second thing')
                done(new Error('another thing'))
            }
        ], function(err, result) {

            if (err) {
                return Promise.reject(err);
            }
            return Promise.resolve(result);
        })
    }
}

I hope to then use the class this way

var testClass = new MyClass();
testClass.run().then(function(){
  // results from the "series" function
})

But I cant seem to get the promise to be handed over to the class instance method run(). Does anyone have an idea what I am doing wrong? thnaks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.