Giter Site home page Giter Site logo

run-auto's Introduction

run-auto travis npm downloads javascript style guide

Determine the best order for running async functions, LIKE MAGIC!

auto Sauce Test Status

install

npm install run-auto

usage

auto(tasks, [callback])

Determines the best order for running the functions in tasks, based on their requirements. Each function can optionally depend on other functions being completed first, and each function is run as soon as its requirements are satisfied.

If any of the functions pass an error to their callback, the auto sequence will stop. Further tasks will not execute (so any other functions depending on it will not run), and the main callback is immediately called with the error.

Functions also receive an object containing the results of functions which have completed so far as the first argument, if they have dependencies. If a task function has no dependencies, it will only be passed a callback.

arguments
  • tasks - An object. Each of its properties is either a function or an array of requirements, with the function itself the last item in the array. The object's key of a property serves as the name of the task defined by that property, i.e. can be used when specifying requirements for other tasks. The function receives one or two arguments:
    • a results object, containing the results of the previously executed functions, only passed if the task has any dependencies, Argument order changed in 2.0
    • a callback(err, result) function, which must be called when finished, passing an error (which can be null) and the result of the function's execution. Argument order changed in 2.0
  • callback(err, results) - An optional callback which is called when all the tasks have been completed. It receives the err argument if any tasks pass an error to their callback. Results are always returned; however, if an error occurs, no further tasks will be performed, and the results object will only contain partial results.
example
var auto = require('run-auto')

auto({
  getData: function (callback) {
    console.log('in getData')
    // async code to get some data
    callback(null, 'data', 'converted to array')
  },
  makeFolder: function (callback) {
    console.log('in makeFolder')
    // async code to create a directory to store a file in
    // this is run at the same time as getting the data
    callback(null, 'folder')
  },
  writeFile: ['getData', 'makeFolder', function (results, callback) {
    console.log('in writeFile', JSON.stringify(results))
    // once there is some data and the directory exists,
    // write the data to a file in the directory
    callback(null, 'filename')
  }],
  emailLink: ['writeFile', function (results, callback) {
    console.log('in emailLink', JSON.stringify(results))
    // once the file is written let's email a link to it...
    // results.writeFile contains the filename returned by writeFile.
    callback(null, { file: results.writeFile, email: '[email protected]' })
  }]
}, function(err, results) {
  console.log('err = ', err)
  console.log('results = ', results)
})

usage note

Note, all functions are called with a results object as a second argument, so it is unsafe to pass functions in the tasks object which cannot handle the extra argument.

For example, this snippet of code:

auto({
  readData: async.apply(fs.readFile, 'data.txt', 'utf-8')
}, callback)

will have the effect of calling readFile with the results object as the last argument, which will fail, like this:

fs.readFile('data.txt', 'utf-8', cb, {})

Instead, wrap the call to readFile in a function which does not forward the results object:

auto({
  readData: function (cb, results) {
    fs.readFile('data.txt', 'utf-8', cb)
  }
}, callback)

This module is basically equavalent to async.auto, but it's handy to just have the one function you need instead of the kitchen sink. Modularity! Especially handy if you're serving to the browser and need to reduce your javascript bundle size.

Works great in the browser with browserify!

see also

license

MIT. Copyright (c) Feross Aboukhadijeh.

Image credit: Wizard Hat designed by Andrew Fortnum

run-auto's People

Contributors

feross avatar greenkeeper[bot] avatar greenkeeperio-bot avatar nizaroni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

run-auto's Issues

An in-range update of tape is breaking the build 🚨

Version 4.9.1 of tape was just published.

Branch Build failing 🚨
Dependency tape
Current Version 4.9.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

tape is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 10 commits.

  • 050b318 v4.9.1
  • 73232c0 [Dev Deps] update js-yaml
  • 8a2d29b [Deps] update has, for-each, resolve, object-inspect
  • c6f5313 [Tests] add eclint and eslint, to enforce a consistent style
  • 45788a5 [Dev Deps] update concat-stream
  • ec4a71d [fix] Fix bug in functionName regex during stack parsing
  • 7261ccc Merge pull request #433 from mcnuttandrew/add-trb
  • 6cbc53e Add tap-react-browser
  • 9d501ff [Dev Deps] use ~ for dev deps; update to latest nonbreaking
  • 24e0a8d Fix spelling of "parameterize"

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of tape is breaking the build 🚨

The devDependency tape was updated from 4.13.0 to 4.13.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

tape is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 9 commits.

  • 2914a7b v4.13.2
  • c4119c2 [patch] Print name of test that didnt end (#498)
  • 98b2695 [Tests] sync new test cases from master
  • d686aa2 [eslint] enable quotes rule
  • 4526b39 [Tests] add tests for edge cases and numerics
  • 398503c [Deps] update resolve
  • e6b6f11 [Refactor] remove unused code
  • 333c636 v4.13.1
  • 8af61fd [Fix] match/doesNotMatch: when passing, ensure the proper default assert message shows up

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of standard is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 11.0.1 of standard was just published.

Branch Build failing 🚨
Dependency standard
Current Version 11.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

standard is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 20 commits.

  • 670a3be authors
  • b7e6cbc 11.0.1
  • 34a3c40 Merge pull request #1092 from watson/elastic-logo
  • 5382643 Replace Opbeat with Elastic logo
  • c40c799 Merge pull request #1091 from mackermans/master
  • 504fcff docs(README): update typeform logo
  • a5b779f Swap README.md and RULES.md symlinks (#1090)
  • e818224 Merge pull request #1072 from standard/greenkeeper/eslint-plugin-react-7.7.0
  • 9dc888f Merge branch 'master' into greenkeeper/eslint-plugin-react-7.7.0
  • a5293dd Merge pull request #1075 from standard/greenkeeper/eslint-plugin-import-2.9.0
  • ebf6620 Merge pull request #1087 from standard/greenkeeper/eslint-plugin-promise-3.7.0
  • 116a871 fix(package): update eslint-plugin-promise to version 3.7.0
  • 738edc4 readme: add standard talk
  • c93ac0d Merge pull request #1076 from tumobi/fix-links
  • 4f8c1f5 Fix webstorm.md links

There are 20 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.