All Projects → feross → run-auto

feross / run-auto

Licence: MIT license
Determine the best order for running async functions, LIKE MAGIC!

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to run-auto

Babel Plugin React Intl Auto
i18n for the component age. Auto management react-intl ID.
Stars: ✭ 203 (+147.56%)
Mutual labels:  auto
Android-Touch-Helper
开屏跳过-安卓系统的开屏广告自动跳过助手
Stars: ✭ 488 (+495.12%)
Mutual labels:  auto
MudaeAutoBot
python bot that uses strictly the **Discord API** to Roll,Claim,and Kakera Snipe in Mudae. 5/10/21 project converted over to discum library
Stars: ✭ 102 (+24.39%)
Mutual labels:  auto
Unity-2017.2-and-Vuforia-6.5---Camera-Auto-Focus
Unity 2017.2 and Vuforia 6.5 Augmented Reality (AR) Camera Auto Focus
Stars: ✭ 17 (-79.27%)
Mutual labels:  auto
linkedin-auto-connect
💥 An automation tool to automate the connection requests on LinkedIn
Stars: ✭ 87 (+6.1%)
Mutual labels:  auto
samp-discord-plugin
SA:MP Discord Rich Presence plugin
Stars: ✭ 63 (-23.17%)
Mutual labels:  auto
Mapper
A simple and easy go tools for auto mapper map to struct, struct to map, struct to struct, slice to slice, map to slice, map to json.
Stars: ✭ 175 (+113.41%)
Mutual labels:  auto
ig-automatic-story-viewer
Python Program To Send Instagram Story Views
Stars: ✭ 17 (-79.27%)
Mutual labels:  auto
WPWatcher
Wordpress Watcher is a wrapper for WPScan that manages scans on multiple sites and reports by email and/or syslog. Schedule scans and get notified when vulnerabilities, outdated plugins and other risks are found.
Stars: ✭ 34 (-58.54%)
Mutual labels:  auto
iSmartAuto2
✨全新思路✨ | iSmart 刷课工具,自动完成任务,一分钟一门课
Stars: ✭ 71 (-13.41%)
Mutual labels:  auto
PengueeBot
Automation tool, visit our discord channel if you have anything to ask
Stars: ✭ 27 (-67.07%)
Mutual labels:  auto
bracket-padder
⌨️ Convenient padding and closing of brackets for Atom
Stars: ✭ 13 (-84.15%)
Mutual labels:  auto
auto-commit-msg
A VS Code extension to generate a smart commit message based on file changes
Stars: ✭ 61 (-25.61%)
Mutual labels:  auto
Kohii
Android Video Playback made easy.
Stars: ✭ 204 (+148.78%)
Mutual labels:  auto
auto-async-wrap
automatic async middleware wrapper for expressjs errorhandler.
Stars: ✭ 21 (-74.39%)
Mutual labels:  auto
Vue Infinite Slide Bar
∞ Infinite slide bar component (no dependency and light weight 1.48 KB)
Stars: ✭ 190 (+131.71%)
Mutual labels:  auto
awake-heroku
A package help your heroku (https://heroku.com/) app is always runs . Wake up your heroku app !
Stars: ✭ 45 (-45.12%)
Mutual labels:  auto
All-in-XrayScan
Xray批量扫描,微信实时推送!
Stars: ✭ 81 (-1.22%)
Mutual labels:  auto
pytibia
🤖 Fastest Tibia PixelBot. A great bot for Auto, Cavebot, Healing, Macro, Refill and Targeting! (Ready To Global)
Stars: ✭ 120 (+46.34%)
Mutual labels:  auto
SuperPuperDuperLayout
Super puper duper mega easy awesome wrapper over auto layout!!111!!1!!!1!!!11111!!!1!!
Stars: ✭ 14 (-82.93%)
Mutual labels:  auto

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].