Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy committed Jun 30, 2023
1 parent 5d3b607 commit bc43849
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @flow
*/

// @ts-ignore
import CoreManager from './CoreManager';

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ParseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2447,11 +2447,11 @@ const DefaultController = {

// Queue up tasks for each object in the batch.
// When every task is ready, the API request will execute
const batchReturned = new resolvingPromise();
const batchReturned = resolvingPromise();
const batchReady: any[] = [];
const batchTasks: any[] = [];
batch.forEach((obj, index) => {
const ready = new resolvingPromise();
const ready = resolvingPromise();
batchReady.push(ready);
const task = function () {
ready.resolve();
Expand Down
11 changes: 6 additions & 5 deletions src/TaskQueue.js → src/TaskQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import { resolvingPromise } from './promiseUtils';

type Task = {
task: () => Promise,
_completion: Promise,
task: () => Promise<any>,
_completion: resolvingPromise<Task>,
};

class TaskQueue {
queue: Array<Task>;
queue: Task[];

constructor() {
this.queue = [];
}

enqueue(task: () => Promise): Promise {
const taskComplete = new resolvingPromise();
enqueue(task: () => Promise<any>): Promise<any> {
const taskComplete = resolvingPromise();
this.queue.push({
task: task,
_completion: taskComplete,
Expand Down Expand Up @@ -55,3 +55,4 @@ class TaskQueue {
}

module.exports = TaskQueue;
export default TaskQueue;
13 changes: 9 additions & 4 deletions src/promiseUtils.js → src/promiseUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// Create Deferred Promise
export interface resolvingPromise<T> extends Promise<T> {
resolve?:(value?: any) => void;
reject?:(value?: any) => void;
}

export function resolvingPromise() {
let res;
let rej;
const promise = new Promise((resolve, reject) => {
let res: (value: any) => void | null;
let rej: (value: any) => void | null;
const promise: resolvingPromise<any> = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
Expand Down Expand Up @@ -32,7 +37,7 @@ export function when(promises) {
return Promise.resolve(returnValue);
}

const promise = new resolvingPromise();
const promise = resolvingPromise();

const resolveOne = function () {
total--;
Expand Down
15 changes: 15 additions & 0 deletions types/TaskQueue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @flow
*/
import { resolvingPromise } from './promiseUtils';
type Task = {
task: () => Promise<any>;
_completion: resolvingPromise<Task>;
};
declare class TaskQueue {
queue: Task[];
constructor();
enqueue(task: () => Promise<any>): Promise<any>;
_dequeue(): void;
}
export default TaskQueue;
7 changes: 7 additions & 0 deletions types/promiseUtils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface resolvingPromise<T> extends Promise<T> {
resolve?: (value?: any) => void;
reject?: (value?: any) => void;
}
export declare function resolvingPromise(): resolvingPromise<any>;
export declare function when(promises: any): resolvingPromise<any> | Promise<any[]>;
export declare function continueWhile(test: any, emitter: any): any;

0 comments on commit bc43849

Please sign in to comment.