Task_Array_Util

//https://stackoverflow.com/questions/15504921/asynchronous-loop-of-jquery-deferreds-promises?answertab=votes#tab-top

Version vom 01.06.2020. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greatest.deepsurf.us/scripts/404464/811172/Task_Array_Util.js

  1. // ==UserScript==
  2. // @name Task_Array_Util
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description //https://stackoverflow.com/questions/15504921/asynchronous-loop-of-jquery-deferreds-promises?answertab=votes#tab-top
  6. // @author Dylan Banta
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. /*
  11. TODO Description
  12. */
  13.  
  14. function doTask(taskNum) {
  15. log("doTask Enter");
  16. var time = Math.floor(Math.random() * 3000);
  17.  
  18. setTimeout(function () {
  19. console.log(taskNum);
  20. dequeTask();
  21. }, time)
  22. }
  23.  
  24. function createTask(taskNum) {
  25. log("createTask Enter");
  26. return function () {
  27. doTask(taskNum);
  28. }
  29. }
  30.  
  31. function queueTask(tasks) {
  32. log("queTask Enter");
  33. //Loops through task array
  34. for (var i in tasks) {
  35. $(document).queue('tasks', function(){
  36. createTask(tasks[i]);
  37. });
  38. }
  39.  
  40. //Add a logger to the end of the task stating that all tasks have been completed
  41. $(document).queue('tasks', function () {
  42. log("All tasks completed");
  43. });
  44. }
  45.  
  46. function dequeueTask() {
  47. $(document).dequeue('tasks');
  48. }