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.

test.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. const waterfall = require('./index');
  3. var generateSyncTask = function(index) {
  4. return function (x){
  5. return function(cb){
  6. console.log(x);
  7. cb(null);
  8. };
  9. }(index);
  10. };
  11. var generateAsyncTask = function(index) {
  12. return function (x){
  13. return function(cb){
  14. setTimeout(function(){
  15. console.log(x);
  16. cb(null);
  17. }, 0);
  18. };
  19. }(index);
  20. };
  21. var generateSyncTasks = function(count){
  22. var tasks = [];
  23. for(var i=0; i<count; i++) {
  24. tasks.push(generateSyncTask(i));
  25. }
  26. return tasks;
  27. }
  28. var generateAsyncTasks = function(count){
  29. var tasks = [];
  30. for(var i=0; i<count; i++) {
  31. tasks.push(generateAsyncTask(i));
  32. }
  33. return tasks;
  34. }
  35. var generateRandomTasks = function(count){
  36. var tasks = [];
  37. for(var i=0; i<count; i++) {
  38. Math.random() > .5 ? tasks.push(generateAsyncTask(i)) : tasks.push(generateSyncTask(i))
  39. }
  40. return tasks;
  41. }
  42. var done = function(){
  43. console.log('done');
  44. }
  45. var testSync = function(){
  46. waterfall(generateSyncTasks(10), done);
  47. console.log('this text should be after waterfall');
  48. };
  49. var testAsync = function(){
  50. waterfall(generateAsyncTasks(5), done);
  51. console.log('this text should be before waterfall');
  52. };
  53. var testMixed = function(){
  54. waterfall(generateRandomTasks(20), done);
  55. };
  56. console.log('testSync:');
  57. testSync();
  58. // console.log('\ntestAsync: ');
  59. // testAsync();
  60. console.log('\ntestMixed: ');
  61. testMixed();