From 789b5e8edabf4fd720fb44f2bea5569bae6511bd Mon Sep 17 00:00:00 2001 From: Sergey Peshkov Date: Tue, 9 Apr 2019 17:05:15 +0300 Subject: [PATCH 1/3] action-queue-config: add option to disable action queue --- src/action-queue.js | 9 +++++++-- src/loader.js | 2 +- tests/loader.tests.js | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/action-queue.js b/src/action-queue.js index 3cb510c..2f1bfb2 100644 --- a/src/action-queue.js +++ b/src/action-queue.js @@ -1,6 +1,6 @@ define(['Emitter'], function(Emitter) { - function ActionQueue() { + function ActionQueue(options) { Emitter.apply(this); this._queue = []; @@ -8,6 +8,11 @@ define(['Emitter'], function(Emitter) { this._id = 0; this._lastQueueItem = void 0; this._endedCount = -1; + + this._options = { + // Включает режим выполнения всех без исключения экшнов без блокировок + forceParallel: options.forceParallel + } } ActionQueue.PRIORITY_HIGH = 1; @@ -20,7 +25,7 @@ define(['Emitter'], function(Emitter) { // TODO: arg types check // Проставляем по умолчанию наивысший приоритет - if (action.priority == null) { + if (action.priority == null || this._options.forceParallel) { action.priority = ActionQueue.PRIORITY_HIGH; } diff --git a/src/loader.js b/src/loader.js index 8791f48..9aa1073 100644 --- a/src/loader.js +++ b/src/loader.js @@ -51,7 +51,7 @@ define(['./match', './action-queue'], function (match, ActionQueue) { // Дебаг-режим, выводит в performance все экшны this._debug = false; // Очередь экшнов - this._actionQueue = new ActionQueue(); + this._actionQueue = new ActionQueue(this._options); this.names.forEach(function (name) { this._index[name] = _cast(name, models[name]); diff --git a/tests/loader.tests.js b/tests/loader.tests.js index 7f86cac..5a3a8a3 100644 --- a/tests/loader.tests.js +++ b/tests/loader.tests.js @@ -10,7 +10,7 @@ function sleep(milliseconds) { } // Этот загрузчик любит спать и писать об этом в лог -async function createSleepyLoggingLoader(log, {persist} = {persist: false}) { +async function createSleepyLoggingLoader(log, {persist, forceParallel} = {persist: false, forceParallel: false}) { const loader = new Loader({ // Этот "переход по маршруту" будет просто ждать нужное кол-во милилсекунд // Ещё он может зависнуть, т.е. вернуть промис, который не разрезолвится никогда @@ -24,6 +24,7 @@ async function createSleepyLoggingLoader(log, {persist} = {persist: false}) { } }, { persist, + forceParallel, processing(request, action, models) { log.push(models.data); } @@ -246,5 +247,17 @@ describe('Loader', () => { await loader.dispatch({timeout: 40, priority: Loader.PRIORITY_HIGH}); expect(log).toEqual(['timeout 40']); - }) + }); + + test('dispatch high after low priority with forceParallel', async () => { + const log = []; + const loader = await createSleepyLoggingLoader(log, {forceParallel: true}); + + loader.dispatch({timeout: 20, priority: Loader.PRIORITY_LOW}); + loader.dispatch({timeout: 10, priority: Loader.PRIORITY_HIGH}); + + await sleep(100); + + expect(log).toEqual(['timeout 10', 'timeout 20']); + }); }); From 64aec5136953127ede6ebcd4f740632126ea69cd Mon Sep 17 00:00:00 2001 From: Sergey Peshkov Date: Tue, 9 Apr 2019 17:05:27 +0300 Subject: [PATCH 2/3] action-queue-config: rebuild --- Pilot.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Pilot.js b/Pilot.js index 7419dd5..c80cb39 100644 --- a/Pilot.js +++ b/Pilot.js @@ -479,7 +479,7 @@ define('src/match',[], function () { define('src/action-queue',['Emitter'], function(Emitter) { - function ActionQueue() { + function ActionQueue(options) { Emitter.apply(this); this._queue = []; @@ -487,6 +487,11 @@ define('src/action-queue',['Emitter'], function(Emitter) { this._id = 0; this._lastQueueItem = void 0; this._endedCount = -1; + + this._options = { + // Включает режим выполнения всех без исключения экшнов без блокировок + forceParallel: options.forceParallel + } } ActionQueue.PRIORITY_HIGH = 1; @@ -499,7 +504,7 @@ define('src/action-queue',['Emitter'], function(Emitter) { // TODO: arg types check // Проставляем по умолчанию наивысший приоритет - if (action.priority == null) { + if (action.priority == null || this._options.forceParallel) { action.priority = ActionQueue.PRIORITY_HIGH; } @@ -662,7 +667,7 @@ define('src/loader',['./match', './action-queue'], function (match, ActionQueue) // Дебаг-режим, выводит в performance все экшны this._debug = false; // Очередь экшнов - this._actionQueue = new ActionQueue(); + this._actionQueue = new ActionQueue(this._options); this.names.forEach(function (name) { this._index[name] = _cast(name, models[name]); From 6ede12e853640e47e0fe3c347f5265ea017112da Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 2 Aug 2019 13:24:31 +0300 Subject: [PATCH 3/3] + master --- Pilot.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Pilot.js b/Pilot.js index 2db1431..4ae1f05 100644 --- a/Pilot.js +++ b/Pilot.js @@ -17,8 +17,7 @@ }); })(typeof define === 'function' && define.amd ? define : function (deps, callback) { window.Pilot = callback(window.Emitter); - }, function (define) { -define('src/querystring',[], function () { + }, function (define) {define('src/querystring',[], function () { 'use strict'; var encodeURIComponent = window.encodeURIComponent; @@ -2092,4 +2091,4 @@ define('src/pilot.js',[ return Pilot; }); -}); +}); \ No newline at end of file