Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # a-sync-waterfall
  2. Simple, isolated sync/async waterfall module for JavaScript.
  3. Runs an array of functions in series, each passing their results to the next in
  4. the array. However, if any of the functions pass an error to the callback, the
  5. next function is not executed and the main callback is immediately called with
  6. the error.
  7. For browsers and node.js.
  8. ## Installation
  9. * Just include a-sync-waterfall before your scripts.
  10. * `npm install a-sync-waterfall` if you’re using node.js.
  11. ## Usage
  12. * `waterfall(tasks, optionalCallback, forceAsync);`
  13. * **tasks** - An array of functions to run, each function is passed a
  14. `callback(err, result1, result2, ...)` it must call on completion. The first
  15. argument is an error (which can be null) and any further arguments will be
  16. passed as arguments in order to the next task.
  17. * **optionalCallback** - An optional callback to run once all the functions have
  18. completed. This will be passed the results of the last task's callback.
  19. * **forceAsync** An optional flag that force tasks run asynchronously even if they are sync.
  20. ##### Node.js:
  21. ```javascript
  22. var waterfall = require('a-sync-waterfall');
  23. waterfall(tasks, callback);
  24. ```
  25. ##### Browser:
  26. ```javascript
  27. var waterfall = require('a-sync-waterfall');
  28. waterfall(tasks, callback);
  29. // Default:
  30. window.waterfall(tasks, callback);
  31. ```
  32. ##### Tasks as Array of Functions
  33. ```javascript
  34. waterfall([
  35. function(callback){
  36. callback(null, 'one', 'two');
  37. },
  38. function(arg1, arg2, callback){
  39. callback(null, 'three');
  40. },
  41. function(arg1, callback){
  42. // arg1 now equals 'three'
  43. callback(null, 'done');
  44. }
  45. ], function (err, result) {
  46. // result now equals 'done'
  47. });
  48. ```
  49. ##### Derive Tasks from an Array.map
  50. ```javascript
  51. /* basic - no arguments */
  52. waterfall(myArray.map(function (arrayItem) {
  53. return function (nextCallback) {
  54. // same execution for each item, call the next one when done
  55. doAsyncThingsWith(arrayItem, nextCallback);
  56. }}));
  57. /* with arguments, initializer function, and final callback */
  58. waterfall([function initializer (firstMapFunction) {
  59. firstMapFunction(null, initialValue);
  60. }].concat(myArray.map(function (arrayItem) {
  61. return function (lastItemResult, nextCallback) {
  62. // same execution for each item in the array
  63. var itemResult = doThingsWith(arrayItem, lastItemResult);
  64. // results carried along from each to the next
  65. nextCallback(null, itemResult);
  66. }})), function (err, finalResult) {
  67. // final callback
  68. });
  69. ```
  70. ## Acknowledgements
  71. Hat tip to [Caolan McMahon](https://github.com/caolan) and
  72. [Paul Miller](https://github.com/paulmillr), whose prior contributions this is
  73. based upon.
  74. Also [Elan Shanker](https://github.com/es128) from which this rep is forked
  75. ## License
  76. [MIT](https://raw.github.com/hydiak/a-sync-waterfall/master/LICENSE)