Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Namespace | |
| 6 var importer; | |
| 7 | |
| 8 /** | |
| 9 * A queue of tasks. Tasks (subclasses of TaskQueue.Task) can be pushed onto | |
| 10 * the queue. The queue becomes active whenever it is not empty, and it will | |
| 11 * begin executing tasks one at a time. The tasks are executed in a separate | |
| 12 * asynchronous context. As each task runs, it can send update notifications | |
| 13 * which are relayed back to clients via callbacks. When the queue runs of of | |
| 14 * tasks, it goes back into an idle state. Clients can set callbacks which will | |
| 15 * be triggered whenever the queue transitions between the active and idle | |
| 16 * states. | |
| 17 * | |
| 18 * @constructor | |
| 19 * @struct | |
| 20 */ | |
| 21 importer.TaskQueue = function() {}; | |
|
fukino
2017/05/17 04:58:56
Do we have to expose full shape of importer.TaskQu
oka
2017/05/17 08:45:42
Removed needless exposure.
| |
| 22 | |
| 23 /** | |
| 24 * @enum {string} | |
| 25 */ | |
| 26 importer.TaskQueue.UpdateType = {}; | |
| 27 | |
| 28 | |
| 29 /** | |
| 30 * @param {!importer.TaskQueue.Task} task | |
| 31 */ | |
| 32 importer.TaskQueue.prototype.queueTask = function(task) {}; | |
| 33 | |
| 34 /** | |
| 35 * Sets a callback to be triggered when a task updates. | |
| 36 * @param {function(string, !importer.TaskQueue.Task)} callback | |
| 37 */ | |
| 38 importer.TaskQueue.prototype.addUpdateCallback = function(callback) {}; | |
| 39 | |
| 40 /** | |
| 41 * Sets a callback that is triggered each time the queue goes from an idle | |
| 42 * (i.e. empty with no running tasks) to an active (i.e. having a running task) | |
| 43 * state. | |
| 44 * @param {function()} callback | |
| 45 */ | |
| 46 importer.TaskQueue.prototype.setActiveCallback = function(callback) {}; | |
| 47 | |
| 48 /** | |
| 49 * Sets a callback that is triggered each time the queue goes from an active to | |
| 50 * an idle state. Also see #setActiveCallback. | |
| 51 * @param {function()} callback | |
| 52 */ | |
| 53 importer.TaskQueue.prototype.setIdleCallback = function(callback) {}; | |
| 54 | |
| 55 /** | |
| 56 * Interface for any Task that is to run on the TaskQueue. | |
| 57 * @interface | |
| 58 */ | |
| 59 importer.TaskQueue.Task = function() {}; | |
| 60 | |
| 61 /** | |
| 62 * A callback that is triggered whenever an update is reported on the observed | |
| 63 * task. The first argument is a string specifying the type of the update. | |
| 64 * Standard values used by all tasks are enumerated in | |
| 65 * importer.TaskQueue.UpdateType, but child classes may add supplementary update | |
| 66 * types of their own. The second argument is an Object containing | |
| 67 * supplementary information pertaining to the update. | |
| 68 * @typedef {function(!importer.TaskQueue.UpdateType, Object=)} | |
| 69 */ | |
| 70 importer.TaskQueue.Task.Observer; | |
| 71 | |
| 72 /** | |
| 73 * Sets the TaskQueue that will own this task. The TaskQueue must call this | |
| 74 * prior to enqueuing a Task. | |
| 75 * @param {!importer.TaskQueue.Task.Observer} observer A callback that | |
| 76 * will be triggered each time the task has a status update. | |
| 77 */ | |
| 78 importer.TaskQueue.Task.prototype.addObserver; | |
| 79 | |
| 80 /** | |
| 81 * Performs the actual work of the Task. Child classes should implement this. | |
| 82 */ | |
| 83 importer.TaskQueue.Task.prototype.run; | |
| 84 | |
| 85 /** | |
| 86 * Base class for importer tasks. | |
| 87 * @constructor | |
| 88 * @implements {importer.TaskQueue.Task} | |
| 89 */ | |
| 90 importer.TaskQueue.BaseTask = function() {}; | |
| 91 | |
| 92 /** @struct */ | |
| 93 importer.TaskQueue.BaseTask.prototype = { | |
| 94 /** @return {string} The task ID. */ | |
| 95 get taskId() {}, | |
| 96 | |
| 97 /** @return {!Promise<!importer.TaskQueue.UpdateType>} Resolves when task | |
| 98 is complete, or cancelled, rejects on error. */ | |
| 99 get whenFinished() {} | |
| 100 }; | |
| 101 | |
| 102 /** @override */ | |
| 103 importer.TaskQueue.BaseTask.prototype.addObserver = function(observer) {}; | |
| 104 | |
| 105 /** @override */ | |
| 106 importer.TaskQueue.BaseTask.prototype.run = function() {}; | |
| 107 | |
| 108 /** | |
| 109 * @param {string} updateType | |
| 110 * @param {Object=} opt_data | |
| 111 * @protected | |
| 112 */ | |
| 113 importer.TaskQueue.BaseTask.prototype.notify = function(updateType, opt_data) { | |
| 114 }; | |
| OLD | NEW |