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.

index.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // MIT license (by Elan Shanker).
  2. (function(globals) {
  3. 'use strict';
  4. var executeSync = function(){
  5. var args = Array.prototype.slice.call(arguments);
  6. if (typeof args[0] === 'function'){
  7. args[0].apply(null, args.splice(1));
  8. }
  9. };
  10. var executeAsync = function(fn){
  11. if (typeof setImmediate === 'function') {
  12. setImmediate(fn);
  13. } else if (typeof process !== 'undefined' && process.nextTick) {
  14. process.nextTick(fn);
  15. } else {
  16. setTimeout(fn, 0);
  17. }
  18. };
  19. var makeIterator = function (tasks) {
  20. var makeCallback = function (index) {
  21. var fn = function () {
  22. if (tasks.length) {
  23. tasks[index].apply(null, arguments);
  24. }
  25. return fn.next();
  26. };
  27. fn.next = function () {
  28. return (index < tasks.length - 1) ? makeCallback(index + 1): null;
  29. };
  30. return fn;
  31. };
  32. return makeCallback(0);
  33. };
  34. var _isArray = Array.isArray || function(maybeArray){
  35. return Object.prototype.toString.call(maybeArray) === '[object Array]';
  36. };
  37. var waterfall = function (tasks, callback, forceAsync) {
  38. var nextTick = forceAsync ? executeAsync : executeSync;
  39. callback = callback || function () {};
  40. if (!_isArray(tasks)) {
  41. var err = new Error('First argument to waterfall must be an array of functions');
  42. return callback(err);
  43. }
  44. if (!tasks.length) {
  45. return callback();
  46. }
  47. var wrapIterator = function (iterator) {
  48. return function (err) {
  49. if (err) {
  50. callback.apply(null, arguments);
  51. callback = function () {};
  52. } else {
  53. var args = Array.prototype.slice.call(arguments, 1);
  54. var next = iterator.next();
  55. if (next) {
  56. args.push(wrapIterator(next));
  57. } else {
  58. args.push(callback);
  59. }
  60. nextTick(function () {
  61. iterator.apply(null, args);
  62. });
  63. }
  64. };
  65. };
  66. wrapIterator(makeIterator(tasks))();
  67. };
  68. if (typeof define !== 'undefined' && define.amd) {
  69. define([], function () {
  70. return waterfall;
  71. }); // RequireJS
  72. } else if (typeof module !== 'undefined' && module.exports) {
  73. module.exports = waterfall; // CommonJS
  74. } else {
  75. globals.waterfall = waterfall; // <script>
  76. }
  77. })(this);