Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function synchronizedFor (_start, _end, _iteration) {
- return new Promise (function (resolveAll, rejectAll) {
- var currentIndex = _start;
- var isPromisInProgres = false;
- var interval = setInterval (function () {
- if (!isPromisInProgres) {
- if (currentIndex >= _end) {
- clearInterval (interval);
- resolveAll ();
- }
- else {
- new Promise (function (resolve, reject) {
- isPromisInProgres = true;
- _iteration (currentIndex, resolve);
- }).then (function () {
- isPromisInProgres = false;
- ++currentIndex;
- });
- }
- }
- }, 50);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement