How to use queueTask method in wpt

Best JavaScript code snippet using wpt

promise-rejection-events.js

Source:promise-rejection-events.js Github

copy

Full Screen

...26 var e = new Error();27 var p;28 onUnhandledSucceed(t, e, function() { return p; });29 p = new Promise(function(_, reject) {30 queueTask(function() {31 reject(e);32 });33 });34}, 'unhandledrejection: from a task-delayed rejection');35async_test(function(t) {36 var e = new Error();37 var p;38 onUnhandledSucceed(t, e, function() { return p; });39 p = new Promise(function(_, reject) {40 setTimeout(function() {41 reject(e);42 }, 1);43 });44}, 'unhandledrejection: from a setTimeout-delayed rejection');45async_test(function(t) {46 var e = new Error();47 var e2 = new Error();48 var promise2;49 onUnhandledSucceed(t, e2, function() { return promise2; });50 var unreached = t.unreached_func('promise should not be fulfilled');51 promise2 = Promise.reject(e).then(unreached, function(reason) {52 t.step(function() {53 assert_equals(reason, e);54 });55 throw e2;56 });57}, 'unhandledrejection: from a throw in a rejection handler chained off of Promise.reject');58async_test(function(t) {59 var e = new Error();60 var e2 = new Error();61 var promise2;62 onUnhandledSucceed(t, e2, function() { return promise2; });63 var unreached = t.unreached_func('promise should not be fulfilled');64 promise2 = new Promise(function(_, reject) {65 setTimeout(function() {66 reject(e);67 }, 1);68 }).then(unreached, function(reason) {69 t.step(function() {70 assert_equals(reason, e);71 });72 throw e2;73 });74}, 'unhandledrejection: from a throw in a rejection handler chained off of a setTimeout-delayed rejection');75async_test(function(t) {76 var e = new Error();77 var e2 = new Error();78 var promise2;79 onUnhandledSucceed(t, e2, function() { return promise2; });80 var promise = new Promise(function(_, reject) {81 setTimeout(function() {82 reject(e);83 mutationObserverMicrotask(function() {84 var unreached = t.unreached_func('promise should not be fulfilled');85 promise2 = promise.then(unreached, function(reason) {86 t.step(function() {87 assert_equals(reason, e);88 });89 throw e2;90 });91 });92 }, 1);93 });94}, 'unhandledrejection: from a throw in a rejection handler attached one microtask after a setTimeout-delayed rejection');95async_test(function(t) {96 var e = new Error();97 var p;98 onUnhandledSucceed(t, e, function() { return p; });99 p = Promise.resolve().then(function() {100 return Promise.reject(e);101 });102}, 'unhandledrejection: from returning a Promise.reject-created rejection in a fulfillment handler');103async_test(function(t) {104 var e = new Error();105 var p;106 onUnhandledSucceed(t, e, function() { return p; });107 p = Promise.resolve().then(function() {108 throw e;109 });110}, 'unhandledrejection: from a throw in a fulfillment handler');111async_test(function(t) {112 var e = new Error();113 var p;114 onUnhandledSucceed(t, e, function() { return p; });115 p = Promise.resolve().then(function() {116 return new Promise(function(_, reject) {117 setTimeout(function() {118 reject(e);119 }, 1);120 });121 });122}, 'unhandledrejection: from returning a setTimeout-delayed rejection in a fulfillment handler');123async_test(function(t) {124 var e = new Error();125 var p;126 onUnhandledSucceed(t, e, function() { return p; });127 p = Promise.all([Promise.reject(e)]);128}, 'unhandledrejection: from Promise.reject, indirected through Promise.all');129async_test(function(t) {130 var p;131 var unhandled = function(ev) {132 if (ev.promise === p) {133 t.step(function() {134 assert_equals(ev.reason.name, 'InvalidStateError');135 assert_equals(ev.promise, p);136 });137 t.done();138 }139 };140 addEventListener('unhandledrejection', unhandled);141 ensureCleanup(t, unhandled);142 p = createImageBitmap(new Blob());143}, 'unhandledrejection: from createImageBitmap which is UA triggered');144//145// Negative unhandledrejection/rejectionhandled tests with immediate attachment146//147async_test(function(t) {148 var e = new Error();149 var p;150 onUnhandledFail(t, function() { return p; });151 var unreached = t.unreached_func('promise should not be fulfilled');152 p = Promise.reject(e).then(unreached, function() {});153}, 'no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a promise from Promise.reject');154async_test(function(t) {155 var e = new Error();156 var p;157 onUnhandledFail(t, function() { return p; });158 var unreached = t.unreached_func('promise should not be fulfilled');159 p = Promise.all([Promise.reject(e)]).then(unreached, function() {});160}, 'no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a promise from ' +161 'Promise.reject, indirecting through Promise.all');162async_test(function(t) {163 var e = new Error();164 var p;165 onUnhandledFail(t, function() { return p; });166 var unreached = t.unreached_func('promise should not be fulfilled');167 p = new Promise(function(_, reject) {168 reject(e);169 }).then(unreached, function() {});170}, 'no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a synchronously-rejected ' +171 'promise created with new Promise');172async_test(function(t) {173 var e = new Error();174 var p;175 onUnhandledFail(t, function() { return p; });176 var unreached = t.unreached_func('promise should not be fulfilled');177 p = Promise.resolve().then(function() {178 throw e;179 }).then(unreached, function(reason) {180 t.step(function() {181 assert_equals(reason, e);182 });183 });184}, 'no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a promise created from ' +185 'throwing in a fulfillment handler');186async_test(function(t) {187 var e = new Error();188 var p;189 onUnhandledFail(t, function() { return p; });190 var unreached = t.unreached_func('promise should not be fulfilled');191 p = Promise.resolve().then(function() {192 return Promise.reject(e);193 }).then(unreached, function(reason) {194 t.step(function() {195 assert_equals(reason, e);196 });197 });198}, 'no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a promise created from ' +199 'returning a Promise.reject-created promise in a fulfillment handler');200async_test(function(t) {201 var e = new Error();202 var p;203 onUnhandledFail(t, function() { return p; });204 var unreached = t.unreached_func('promise should not be fulfilled');205 p = Promise.resolve().then(function() {206 return new Promise(function(_, reject) {207 setTimeout(function() {208 reject(e);209 }, 1);210 });211 }).then(unreached, function(reason) {212 t.step(function() {213 assert_equals(reason, e);214 });215 });216}, 'no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a promise created from ' +217 'returning a setTimeout-delayed rejection in a fulfillment handler');218async_test(function(t) {219 var e = new Error();220 var p;221 onUnhandledFail(t, function() { return p; });222 queueTask(function() {223 p = Promise.resolve().then(function() {224 return Promise.reject(e);225 })226 .catch(function() {});227 });228}, 'no unhandledrejection/rejectionhandled: all inside a queued task, a rejection handler attached synchronously to ' +229 'a promise created from returning a Promise.reject-created promise in a fulfillment handler');230async_test(function(t) {231 var p;232 onUnhandledFail(t, function() { return p; });233 var unreached = t.unreached_func('promise should not be fulfilled');234 p = createImageBitmap(new Blob()).then(unreached, function() {});235}, 'no unhandledrejection/rejectionhandled: rejection handler attached synchronously to a promise created from ' +236 'createImageBitmap');237//238// Negative unhandledrejection/rejectionhandled tests with microtask-delayed attachment239//240async_test(function(t) {241 var e = new Error();242 var p;243 onUnhandledFail(t, function() { return p; });244 p = Promise.reject(e);245 mutationObserverMicrotask(function() {246 var unreached = t.unreached_func('promise should not be fulfilled');247 p.then(unreached, function() {});248 });249}, 'delayed handling: a microtask delay before attaching a handler prevents both events (Promise.reject-created ' +250 'promise)');251async_test(function(t) {252 var e = new Error();253 var p;254 onUnhandledFail(t, function() { return p; });255 p = new Promise(function(_, reject) {256 reject(e);257 });258 mutationObserverMicrotask(function() {259 var unreached = t.unreached_func('promise should not be fulfilled');260 p.then(unreached, function() {});261 });262}, 'delayed handling: a microtask delay before attaching a handler prevents both events (immediately-rejected new ' +263 'Promise-created promise)');264async_test(function(t) {265 var e = new Error();266 var p1;267 var p2;268 onUnhandledFail(t, function() { return p1; });269 onUnhandledFail(t, function() { return p2; });270 p1 = new Promise(function(_, reject) {271 mutationObserverMicrotask(function() {272 reject(e);273 });274 });275 p2 = Promise.all([p1]);276 mutationObserverMicrotask(function() {277 var unreached = t.unreached_func('promise should not be fulfilled');278 p2.then(unreached, function() {});279 });280}, 'delayed handling: a microtask delay before attaching the handler, and before rejecting the promise, indirected ' +281 'through Promise.all');282//283// Negative unhandledrejection/rejectionhandled tests with nested-microtask-delayed attachment284//285async_test(function(t) {286 var e = new Error();287 var p;288 onUnhandledFail(t, function() { return p; });289 p = Promise.reject(e);290 mutationObserverMicrotask(function() {291 Promise.resolve().then(function() {292 mutationObserverMicrotask(function() {293 Promise.resolve().then(function() {294 p.catch(function() {});295 });296 });297 });298 });299}, 'microtask nesting: attaching a handler inside a combination of mutationObserverMicrotask + promise microtasks');300async_test(function(t) {301 var e = new Error();302 var p;303 onUnhandledFail(t, function() { return p; });304 queueTask(function() {305 p = Promise.reject(e);306 mutationObserverMicrotask(function() {307 Promise.resolve().then(function() {308 mutationObserverMicrotask(function() {309 Promise.resolve().then(function() {310 p.catch(function() {});311 });312 });313 });314 });315 });316}, 'microtask nesting: attaching a handler inside a combination of mutationObserverMicrotask + promise microtasks, ' +317 'all inside a queueTask');318async_test(function(t) {319 var e = new Error();320 var p;321 onUnhandledFail(t, function() { return p; });322 setTimeout(function() {323 p = Promise.reject(e);324 mutationObserverMicrotask(function() {325 Promise.resolve().then(function() {326 mutationObserverMicrotask(function() {327 Promise.resolve().then(function() {328 p.catch(function() {});329 });330 });331 });332 });333 }, 0);334}, 'microtask nesting: attaching a handler inside a combination of mutationObserverMicrotask + promise microtasks, ' +335 'all inside a setTimeout');336async_test(function(t) {337 var e = new Error();338 var p;339 onUnhandledFail(t, function() { return p; });340 p = Promise.reject(e);341 Promise.resolve().then(function() {342 mutationObserverMicrotask(function() {343 Promise.resolve().then(function() {344 mutationObserverMicrotask(function() {345 p.catch(function() {});346 });347 });348 });349 });350}, 'microtask nesting: attaching a handler inside a combination of promise microtasks + mutationObserverMicrotask');351async_test(function(t) {352 var e = new Error();353 var p;354 onUnhandledFail(t, function() { return p; });355 queueTask(function() {356 p = Promise.reject(e);357 Promise.resolve().then(function() {358 mutationObserverMicrotask(function() {359 Promise.resolve().then(function() {360 mutationObserverMicrotask(function() {361 p.catch(function() {});362 });363 });364 });365 });366 });367}, 'microtask nesting: attaching a handler inside a combination of promise microtasks + mutationObserverMicrotask, ' +368 'all inside a queueTask');369async_test(function(t) {370 var e = new Error();371 var p;372 onUnhandledFail(t, function() { return p; });373 setTimeout(function() {374 p = Promise.reject(e);375 Promise.resolve().then(function() {376 mutationObserverMicrotask(function() {377 Promise.resolve().then(function() {378 mutationObserverMicrotask(function() {379 p.catch(function() {});380 });381 });382 });383 });384 }, 0);385}, 'microtask nesting: attaching a handler inside a combination of promise microtasks + mutationObserverMicrotask, ' +386 'all inside a setTimeout');387// For workers, queueTask() involves posting tasks to other threads, so388// the following tests don't work there.389if ('document' in self) {390 //391 // Negative unhandledrejection/rejectionhandled tests with task-delayed attachment392 //393 async_test(function(t) {394 var e = new Error();395 var p;396 onUnhandledFail(t, function() { return p; });397 var _reject;398 p = new Promise(function(_, reject) {399 _reject = reject;400 });401 _reject(e);402 queueTask(function() {403 var unreached = t.unreached_func('promise should not be fulfilled');404 p.then(unreached, function() {});405 });406 }, 'delayed handling: a task delay before attaching a handler prevents unhandledrejection');407 async_test(function(t) {408 var e = new Error();409 var p;410 onUnhandledFail(t, function() { return p; });411 p = Promise.reject(e);412 queueTask(function() {413 Promise.resolve().then(function() {414 p.catch(function() {});415 });416 });417 }, 'delayed handling: queueTask after promise creation/rejection, plus promise microtasks, is not too late to ' +418 'attach a rejection handler');419 async_test(function(t) {420 var e = new Error();421 var p;422 onUnhandledFail(t, function() { return p; });423 queueTask(function() {424 Promise.resolve().then(function() {425 Promise.resolve().then(function() {426 Promise.resolve().then(function() {427 Promise.resolve().then(function() {428 p.catch(function() {});429 });430 });431 });432 });433 });434 p = Promise.reject(e);435 }, 'delayed handling: queueTask before promise creation/rejection, plus many promise microtasks, is not too ' +436 'late to attach a rejection handler');437 async_test(function(t) {438 var e = new Error();439 var p;440 onUnhandledFail(t, function() { return p; });441 p = Promise.reject(e);442 queueTask(function() {443 Promise.resolve().then(function() {444 Promise.resolve().then(function() {445 Promise.resolve().then(function() {446 Promise.resolve().then(function() {447 p.catch(function() {});448 });449 });450 });451 });452 });453 }, 'delayed handling: queueTask after promise creation/rejection, plus many promise microtasks, is not too ' +454 'late to attach a rejection handler');455}456//457// Positive unhandledrejection/rejectionhandled tests with delayed attachment458//459async_test(function(t) {460 var e = new Error();461 var p;462 onUnhandledSucceed(t, e, function() { return p; });463 var _reject;464 p = new Promise(function(_, reject) {465 _reject = reject;466 });467 _reject(e);468 queueTask(function() {469 queueTask(function() {470 var unreached = t.unreached_func('promise should not be fulfilled');471 p.then(unreached, function() {});472 });473 });474}, 'delayed handling: a nested-task delay before attaching a handler causes unhandledrejection');475async_test(function(t) {476 var e = new Error();477 var p;478 onUnhandledSucceed(t, e, function() { return p; });479 p = Promise.reject(e);480 queueTask(function() {481 queueTask(function() {482 Promise.resolve().then(function() {483 p.catch(function() {});484 });485 });486 });487}, 'delayed handling: a nested-queueTask after promise creation/rejection, plus promise microtasks, is too ' +488 'late to attach a rejection handler');489async_test(function(t) {490 var e = new Error();491 var p;492 onUnhandledSucceed(t, e, function() { return p; });493 queueTask(function() {494 queueTask(function() {495 Promise.resolve().then(function() {496 Promise.resolve().then(function() {497 Promise.resolve().then(function() {498 Promise.resolve().then(function() {499 p.catch(function() {});500 });501 });502 });503 });504 });505 });506 p = Promise.reject(e);507}, 'delayed handling: a nested-queueTask before promise creation/rejection, plus many promise microtasks, is ' +508 'too late to attach a rejection handler');509async_test(function(t) {510 var e = new Error();511 var p;512 onUnhandledSucceed(t, e, function() { return p; });513 p = Promise.reject(e);514 queueTask(function() {515 queueTask(function() {516 Promise.resolve().then(function() {517 Promise.resolve().then(function() {518 Promise.resolve().then(function() {519 Promise.resolve().then(function() {520 p.catch(function() {});521 });522 });523 });524 });525 });526 });527}, 'delayed handling: a nested-queueTask after promise creation/rejection, plus many promise microtasks, is ' +528 'too late to attach a rejection handler');529async_test(function(t) {530 var unhandledPromises = [];531 var unhandledReasons = [];532 var e = new Error();533 var p;534 var unhandled = function(ev) {535 if (ev.promise === p) {536 t.step(function() {537 unhandledPromises.push(ev.promise);538 unhandledReasons.push(ev.reason);539 });540 }541 };542 var handled = function(ev) {543 if (ev.promise === p) {544 t.step(function() {545 assert_array_equals(unhandledPromises, [p]);546 assert_array_equals(unhandledReasons, [e]);547 assert_equals(ev.promise, p);548 assert_equals(ev.reason, e);549 });550 }551 };552 addEventListener('unhandledrejection', unhandled);553 addEventListener('rejectionhandled', handled);554 ensureCleanup(t, unhandled, handled);555 p = new Promise(function() {556 throw e;557 });558 setTimeout(function() {559 var unreached = t.unreached_func('promise should not be fulfilled');560 p.then(unreached, function(reason) {561 assert_equals(reason, e);562 setTimeout(function() { t.done(); }, 10);563 });564 }, 10);565}, 'delayed handling: delaying handling by setTimeout(,10) will cause both events to fire');566async_test(function(t) {567 var unhandledPromises = [];568 var unhandledReasons = [];569 var p;570 var unhandled = function(ev) {571 if (ev.promise === p) {572 t.step(function() {573 unhandledPromises.push(ev.promise);574 unhandledReasons.push(ev.reason.name);575 });576 }577 };578 var handled = function(ev) {579 if (ev.promise === p) {580 t.step(function() {581 assert_array_equals(unhandledPromises, [p]);582 assert_array_equals(unhandledReasons, ['InvalidStateError']);583 assert_equals(ev.promise, p);584 assert_equals(ev.reason.name, 'InvalidStateError');585 });586 }587 };588 addEventListener('unhandledrejection', unhandled);589 addEventListener('rejectionhandled', handled);590 ensureCleanup(t, unhandled, handled);591 p = createImageBitmap(new Blob());592 setTimeout(function() {593 var unreached = t.unreached_func('promise should not be fulfilled');594 p.then(unreached, function(reason) {595 assert_equals(reason.name, 'InvalidStateError');596 setTimeout(function() { t.done(); }, 10);597 });598 }, 10);599}, 'delayed handling: delaying handling rejected promise created from createImageBitmap will cause both events to fire');600//601// Miscellaneous tests about integration with the rest of the platform602//603async_test(function(t) {604 var e = new Error();605 var l = function(ev) {606 var order = [];607 mutationObserverMicrotask(function() {608 order.push(1);609 });610 setTimeout(function() {611 order.push(2);612 t.step(function() {613 assert_array_equals(order, [1, 2]);614 });615 t.done();616 }, 1);617 };618 addEventListener('unhandledrejection', l);619 ensureCleanup(t, l);620 Promise.reject(e);621}, 'mutationObserverMicrotask vs. queueTask ordering is not disturbed inside unhandledrejection events');622// For workers, queueTask() involves posting tasks to other threads, so623// the following tests don't work there.624if ('document' in self) {625 // For the next two see https://github.com/domenic/unhandled-rejections-browser-spec/issues/2#issuecomment-121121695626 // and the following comments.627 async_test(function(t) {628 var sequenceOfEvents = [];629 addEventListener('unhandledrejection', l);630 ensureCleanup(t, l);631 var p1 = Promise.reject();632 var p2;633 queueTask(function() {634 p2 = Promise.reject();635 queueTask(function() {636 sequenceOfEvents.push('queueTask');637 checkSequence();638 });639 });640 function l(ev) {641 if (ev.promise === p1 || ev.promise === p2) {642 sequenceOfEvents.push(ev.promise);643 checkSequence();644 }645 }646 function checkSequence() {647 if (sequenceOfEvents.length === 3) {648 t.step(function() {649 assert_array_equals(sequenceOfEvents, [p1, 'queueTask', p2]);650 });651 t.done();652 }653 }654 }, 'queueTask ordering vs. the task queued for unhandled rejection notification (1)');655 async_test(function(t) {656 var sequenceOfEvents = [];657 addEventListener('unhandledrejection', l);658 ensureCleanup(t, l);659 var p2;660 queueTask(function() {661 p2 = Promise.reject();662 queueTask(function() {663 sequenceOfEvents.push('queueTask');664 checkSequence();665 });666 });667 function l(ev) {668 if (ev.promise == p2) {669 sequenceOfEvents.push(ev.promise);670 checkSequence();671 }672 }673 function checkSequence() {674 if (sequenceOfEvents.length === 2) {675 t.step(function() {676 assert_array_equals(sequenceOfEvents, ['queueTask', p2]);677 });678 t.done();679 }680 }681 }, 'queueTask ordering vs. the task queued for unhandled rejection notification (2)');682 async_test(function(t) {683 var sequenceOfEvents = [];684 addEventListener('unhandledrejection', unhandled);685 addEventListener('rejectionhandled', handled);686 ensureCleanup(t, unhandled, handled);687 var p = Promise.reject();688 function unhandled(ev) {689 if (ev.promise === p) {690 sequenceOfEvents.push('unhandled');691 checkSequence();692 setTimeout(function() {693 queueTask(function() {694 sequenceOfEvents.push('task before catch');695 checkSequence();696 });697 p.catch(function() {698 sequenceOfEvents.push('catch');699 checkSequence();700 });701 queueTask(function() {702 sequenceOfEvents.push('task after catch');703 checkSequence();704 });705 sequenceOfEvents.push('after catch');706 checkSequence();707 }, 10);708 }709 }710 function handled(ev) {711 if (ev.promise === p) {712 sequenceOfEvents.push('handled');713 checkSequence();714 }715 }716 function checkSequence() {717 if (sequenceOfEvents.length === 6) {718 t.step(function() {719 assert_array_equals(sequenceOfEvents,720 ['unhandled', 'after catch', 'catch', 'task before catch', 'handled', 'task after catch']);721 });722 t.done();723 }724 }725 }, 'rejectionhandled is dispatched from a queued task, and not immediately');726}727//728// HELPERS729//730// This function queues a task in "DOM manipulation task source" in window731// context, but not in workers.732function queueTask(f) {733 if ('document' in self) {734 var d = document.createElement("details");735 d.ontoggle = function() {736 f();737 };738 d.setAttribute("open", "");739 } else {740 // We need to fix this to use something that can queue tasks in741 // "DOM manipulation task source" to ensure the order is correct742 var channel = new MessageChannel();743 channel.port1.onmessage = function() { channel.port1.close(); f(); };744 channel.port2.postMessage('abusingpostmessageforfunandprofit');745 channel.port2.close();746 }...

Full Screen

Full Screen

task-queue.ts

Source:task-queue.ts Github

copy

Full Screen

...88 // throw new Error('TaskQueue has already been started');89 // }90 this.platform = options.platform;91 this.allowedExecutionCostWithinTick = options.allowedExecutionCostWithinTick;92 this.task = this.platform.domWriteQueue.queueTask(this.dequeue, { persistent: true });93 }94 public stop(): void {95 // if (!this.isActive) {96 // throw new Error('TaskQueue has not been started');97 // }98 this.task!.cancel();99 this.task = null;100 this.allowedExecutionCostWithinTick = null;101 this.clear();102 }103 public enqueue(item: IQueueableItem<T> | QueueableFunction, cost?: number): QueueTask<T>;104 public enqueue(items: (IQueueableItem<T> | QueueableFunction)[], cost?: number): QueueTask<T>[];105 public enqueue(items: (IQueueableItem<T> | QueueableFunction)[], costs?: number[]): QueueTask<T>[];106 public enqueue(task: QueueTask<T>): QueueTask<T>;107 public enqueue(tasks: QueueTask<T>[]): QueueTask<T>[];108 public enqueue(itemOrItems: IQueueableItem<T> | QueueableFunction | (IQueueableItem<T> | QueueableFunction)[] | QueueTask<T> | QueueTask<T>[], costOrCosts?: number | number[]): QueueTask<T> | QueueTask<T>[] {109 const list: boolean = Array.isArray(itemOrItems);110 const items: (IQueueableItem<T> | QueueTask<T>)[] = (list ? itemOrItems : [itemOrItems]) as (IQueueableItem<T> | QueueTask<T>)[];111 const costs: number[] = items112 .map((value: IQueueableItem<T> | QueueTask<T>, index: number): number | undefined => !Array.isArray(costOrCosts) ? costOrCosts : costOrCosts[index])113 .map((value: number | undefined): number => value !== undefined ? value : 1);114 const tasks: QueueTask<T>[] = [];115 for (const item of items) {116 tasks.push(item instanceof QueueTask117 ? item118 : this.createQueueTask(item, costs.shift())); // TODO: Get cancellable in as well119 }120 this.pending.push(...tasks);121 // if (this.task === null) {122 // this.task = this.platform!.macroTaskQueue.queueTask(this.dequeue, { persistent: true });123 // }124 this.dequeue();125 return list ? tasks : tasks[0];126 }127 public createQueueTask(item: IQueueableItem<T> | QueueableFunction, cost?: number): QueueTask<T> {128 return new QueueTask(this, item, cost);129 }130 public dequeue = (delta?: number): void => {131 if (this.processing !== null) {132 return;133 }134 if (delta !== undefined) {135 this.currentExecutionCostInCurrentTick = 0;136 }137 if (this.pending.length === 0) {138 // if (this.task !== null) {139 // this.task.cancel();140 // this.task = null;141 // }142 return;143 }144 if (this.allowedExecutionCostWithinTick !== null && delta === undefined && this.currentExecutionCostInCurrentTick + (this.pending[0].cost || 0) > this.allowedExecutionCostWithinTick) {145 return;146 }147 this.processing = this.pending.shift() || null;148 if (this.processing) {149 this.currentExecutionCostInCurrentTick += this.processing.cost ?? 0;150 if (this.callback !== void 0) {151 this.callback(this.processing);152 } else {153 // Don't need to await this since next task won't be dequeued until154 // executed function is resolved155 this.processing.execute().catch(error => { throw error; });156 }157 }158 // if (this.pending.length > 0) {159 // this.task = this.platform!.macroTaskQueue.queueTask(this.dequeue);160 // } else {161 // this.task = null;162 // }163 };164 public clear(): void {165 this.pending.length = 0;166 }167 /**168 * @internal169 */170 public resolve(_task: QueueTask<T>, resolve: ((value: void | boolean | PromiseLike<void> | PromiseLike<boolean>) => void)): void {171 resolve();172 this.processing = null;173 this.dequeue();...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const QueueTask = {2 task : [],3 onprocess : null,4 next : null,5 config: {6 disableLogs: false7 }, 8 log : (message, logtype = 'info') => {9 const { config } = QueueTask;10 let color = '\x1b[33m%s\x1b[0m';11 if (config.disableLogs) return;12 13 if (logtype === 'error') color = '\x1b[31m%s\x1b[0m';14 if (logtype === 'success') color = '\x1b[32m%s\x1b[0m';15 if (logtype === 'process') color = '\x1b[34m%s\x1b[0m';16 console.log(color, message);17 },18 uuid : () => 'xxxxxxxx-xxxx-5xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {19 var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);20 return v.toString(16);21 }),22 generateId : () => {23 let tempid = {24 id : null25 };26 tempid['id'] = QueueTask.uuid();27 while (QueueTask.isexists(tempid)) {28 tempid['id'] = QueueTask.uuid();29 }30 31 return tempid['id'];32 },33 isexists : (data) => {34 const size = QueueTask.size();35 let isexists = false;36 37 if (QueueTask.onprocess) {38 if (QueueTask.onprocess?.data?.id === data?.id) {39 return true;40 }41 }42 if (QueueTask.next) {43 if (QueueTask.next?.data?.id === data?.id) {44 return true;45 }46 }47 for (let index = 0; index < size; index++) {48 if (QueueTask.task[index]?.data?.id === data?.id) {49 isexists = true;50 break;51 }52 53 }54 55 return isexists;56 },57 work : (configs = null) => {58 const { config, log } = QueueTask;59 if (configs) {60 QueueTask.config = { ...config, ...configs }61 }62 log('queue:work');63 return QueueTask;64 },65 size : () => QueueTask.length,66 isempty : () => QueueTask.size() === 0,67 enqueue : (data, callback) => { 68 data['id'] = data?.id ?? QueueTask.generateId();69 const _data = {70 data,71 callback72 };73 if (!QueueTask.isexists(data)) {74 if (!QueueTask.onprocess) {75 QueueTask.onprocess = _data;76 QueueTask.process();77 } else {78 if (!QueueTask.next) {79 QueueTask.next = _data;80 } else {81 QueueTask.task.push(_data);82 }83 }84 } else {85 QueueTask.log(`queue:exists TASK ID [${data?.id}]`)86 }87 },88 process : () => {89 if (QueueTask.onprocess) {90 const { data, callback } = QueueTask.onprocess;91 QueueTask.log(`queue:process TASK ID [${data?.id}]`, 'process');92 Promise.resolve(callback(data)).then(QueueTask.dequeue).catch(e => QueueTask.log(e, 'error'))93 } else {94 QueueTask.log('No task to process');95 }96 },97 dequeue : () => {98 QueueTask.log(`queue:done TASK ID [${QueueTask.onprocess?.data?.id}]`, 'success');99 QueueTask.onprocess = QueueTask.next;100 QueueTask.next = (!QueueTask.isempty()) ? QueueTask.task[0] : null;101 QueueTask.task.shift();102 QueueTask.process();103 }104}105 ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 if (err) {4 console.log(err);5 } else {6 console.log('Test ID: ' + data.data.testId);7 console.log('Test Status: ' + data.data.statusText);8 console.log('Test URL: ' + data.data.userUrl);9 console.log('Test Results URL: ' + data.data.summary);10 console.log('Test Results JSON: ' + data.data.jsonUrl);11 }12});13var wpt = require('wpt');14var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');15 if (err) {16 console.log(err);17 } else {18 console.log('Test ID: ' + data.data.testId);19 console.log('Test Status: ' + data.data.statusText);20 console.log('Test URL: ' + data.data.userUrl);21 console.log('Test Results URL: ' + data.data.summary);22 console.log('Test Results JSON: ' + data.data.jsonUrl);23 }24});25var wpt = require('wpt');26var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');27 if (err) {28 console.log(err);29 } else {30 console.log('Test ID: ' + data.data.testId);31 console.log('Test Status: ' + data.data.statusText);32 console.log('Test URL: ' + data.data.userUrl);33 console.log('Test Results URL: ' + data.data.summary

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = wpt('API_KEY');3}, function(err, data) {4 console.log(data);5});6}, function(err, data) {7 console.log(data);8});9}, function(err, data) {10 console.log(data);11});12}, function(err, data) {13 console.log(data);14});15}, function(err, data) {16 console.log(data);17});18}, function(err, data) {19 console.log(data);20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var queueTask = wptoolkit.queueTask;3var task = {4};5queueTask(task, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12var wptoolkit = require('wptoolkit');13var queueTask = wptoolkit.queueTask;14var task = {15};16queueTask(task, function(err, data) {17 if (err) {18 console.log(err);19 } else {20 console.log(data);21 }22});23var wptoolkit = require('wptoolkit');24var queueTask = wptoolkit.queueTask;25var task = {26};27queueTask(task, function(err, data) {28 if (err) {29 console.log(err);30 } else {31 console.log(data);32 }33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webPageTest = new wpt('API_KEY');3var testUrl = 'www.google.com';4var testId = 'testId';5webPageTest.queueTask(testUrl, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 testId = data.data.testId;11 console.log(testId);12 }13});14webPageTest.getTestStatus(testId, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21webPageTest.getTestResults(testId, function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28webPageTest.runTest(testUrl, function(err, data) {29 if (err) {30 console.log(err);31 } else {32 console.log(data);33 }34});35webPageTest.getLocations(function(err, data) {36 if (err) {37 console.log(err);38 } else {39 console.log(data);40 }41});42webPageTest.getTesters(function(err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49webPageTest.getBrowsers(function(err, data) {50 if (err) {51 console.log(err);52 } else {53 console.log(data);54 }55});56webPageTest.getTesters(function(err, data) {57 if (err) {58 console.log(err);59 } else {60 console.log(data);61 }62});63webPageTest.getTesters(function(err, data) {64 if (err) {65 console.log(err);66 } else {67 console.log(data);68 }69});70webPageTest.getTesters(function(err, data) {71 if (

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', 'A.8c8e70e6b7e6f9f9d8c2b2f3cc3c3d1a');5}, function(err, data) {6 if (err) return console.error(err);7 console.log('Test status:', data.statusText);8 if (data.statusCode === 200) {9 console.log('Test completed in', data.data.average.firstView.loadTime, 'ms');10 } else {11 console.log('Test failed');12 }13});14var wpt = require('webpagetest');15var options = {16};17var wpt = new WebPageTest('www.webpagetest.org', 'A.8c8e70e6b7e6f9f9d8c2b2f3cc3c3d1a');18}, function(err, data) {19 if (err) return console.error(err);20 console.log('Test status:', data.statusText);21 if (data.statusCode === 200) {22 console.log('Test completed in', data.data.average.firstView.loadTime, 'ms');23 } else {24 console.log('Test failed');25 }26});27var wpt = require('webpagetest');28var options = {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful