by
27
7
2,193
2
Top 1% !
Popular
Famous
Useful
Easy-to-find
Specified
MultiPlatform
Popularity: 8894th place
Languagejavascript
LicenseMIT_X11

Parallyzed.js.....never move again,.... or do....

.... my pattern for concurrant, Parallel Xekution....sick asyncro stuff!
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/329014/Parallyzed-js-----never-move-again------?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// my pattern for executing a full-on parrallel series of async tasks! function Parallyzed(cBakLst, last) { var rzlts = [], cnt = 0; cBakLst.forEach(function(step, idx) { step(function() { rzlts[idx] = Array.prototype.slice.call(arguments); cnt++; if(cnt == cBakLst.length) { last(rzlts); } }); }); } var taskList = []; function myAsyncTask1(argz, step) { var compRZLT = Math.floor(Math.random() * 5 + 1) * 100; console.log('task with \''+argz+'\', return in '+compRZLT+' ms'); setTimeout(function() { step(argz * 2); }, compRZLT); } taskList.push(myAsyncTask1); function myAsyncTask2(url, cBak) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'JSON'; xhr.onload = function () { if (this.status == 200) { var lst = JSON.parse(xhr.responseText); console.log("paths retreived... "); } cBak(lst); }; xhr.send({}); } taskList.push(myAsyncTask2); function myAsyncTask3(lst, xp, s, cBak) { lst.forEach(function (itm) { var mp = document.createElement('li'); mp.innerHTML = "<a href='#'>" + itm + "</a>"; mp.onclick = wenKlik; xp.appendChild(mp); }); s.appendChild(xp); cBak(s); } taskList.push(myAsyncTask3); function myAsyncTask4(argz, step) { var compRZLT = Math.floor(Math.random() * 5 + 1) * 100; console.log('task with \''+argz+'\', return in '+compRZLT+' ms'); setTimeout(function() { step(arg * 2); }, compRZLT); } taskList.push(myAsyncTask4); function myAsyncTask5(url, argz, step, cBak) { var xhr = new XMLHttpRequest(); xhr.open('POST', url, true); xhr.responseType = 'JSON'; xhr.onload = function () { if (this.status == 200) { var rzlt = JSON.parse(xhr.responseText); } step(cBak(rxlt)); }; xhr.send(argz); } taskList.push(myAsyncTask5); function lastOne(rzlts) { console.log('finished!', rzlts); } Parallyzed(taskList, lastOne);
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus