mirror of https://github.com/status-im/metro.git
packager: AsyncTaskGroup: @flow
Reviewed By: cpojer Differential Revision: D5137195 fbshipit-source-id: 7d61d8f920ea5db7f70415e9f8fb7749a279bec8
This commit is contained in:
parent
76ec909780
commit
e554efaee4
|
@ -5,23 +5,31 @@
|
||||||
* This source code is licensed under the BSD-style license found in the
|
* This source code is licensed under the BSD-style license found in the
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = class AsyncTaskGroup {
|
module.exports = class AsyncTaskGroup<TTaskHandle> {
|
||||||
|
_runningTasks: Set<TTaskHandle>;
|
||||||
|
_resolve: ?() => void;
|
||||||
|
done: Promise<void>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._runningTasks = new Set();
|
this._runningTasks = new Set();
|
||||||
this._resolve = null;
|
this._resolve = null;
|
||||||
this.done = new Promise(resolve => this._resolve = resolve);
|
this.done = new Promise(resolve => this._resolve = resolve);
|
||||||
}
|
}
|
||||||
|
|
||||||
start(taskHandle) {
|
start(taskHandle: TTaskHandle) {
|
||||||
this._runningTasks.add(taskHandle);
|
this._runningTasks.add(taskHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
end(taskHandle) {
|
end(taskHandle: TTaskHandle) {
|
||||||
const runningTasks = this._runningTasks;
|
const runningTasks = this._runningTasks;
|
||||||
if (runningTasks.delete(taskHandle) && runningTasks.size === 0) {
|
if (runningTasks.delete(taskHandle) && runningTasks.size === 0) {
|
||||||
|
/* $FlowFixMe: could be null */
|
||||||
this._resolve();
|
this._resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue