16
16
17
17
import { assert , fail } from './assert' ;
18
18
import * as log from './log' ;
19
- import { AnyJs } from './misc' ;
19
+ import { Unknown } from './misc' ;
20
20
import { Deferred , CancelablePromise } from './promise' ;
21
21
import { Code , FirestoreError } from './error' ;
22
22
@@ -60,7 +60,7 @@ export enum TimerId {
60
60
*
61
61
* Supports cancellation (via cancel()) and early execution (via skipDelay()).
62
62
*/
63
- class DelayedOperation < T > implements CancelablePromise < T > {
63
+ class DelayedOperation < T extends Unknown > implements CancelablePromise < T > {
64
64
// handle for use with clearTimeout(), or null if the operation has been
65
65
// executed or canceled already.
66
66
private timerHandle : TimerHandle | null ;
@@ -94,13 +94,13 @@ class DelayedOperation<T> implements CancelablePromise<T> {
94
94
* PORTING NOTE: This exists to prevent making removeDelayedOperation() and
95
95
* the DelayedOperation class public.
96
96
*/
97
- static createAndSchedule < T > (
97
+ static createAndSchedule < R extends Unknown > (
98
98
asyncQueue : AsyncQueue ,
99
99
timerId : TimerId ,
100
100
delayMs : number ,
101
- op : ( ) => Promise < T > ,
102
- removalCallback : ( op : DelayedOperation < T > ) => void
103
- ) : DelayedOperation < T > {
101
+ op : ( ) => Promise < R > ,
102
+ removalCallback : ( op : DelayedOperation < R > ) => void
103
+ ) : DelayedOperation < R > {
104
104
const targetTime = Date . now ( ) + delayMs ;
105
105
const delayedOp = new DelayedOperation (
106
106
asyncQueue ,
@@ -177,11 +177,11 @@ class DelayedOperation<T> implements CancelablePromise<T> {
177
177
178
178
export class AsyncQueue {
179
179
// The last promise in the queue.
180
- private tail : Promise < AnyJs | void > = Promise . resolve ( ) ;
180
+ private tail : Promise < Unknown > = Promise . resolve ( ) ;
181
181
182
182
// Operations scheduled to be queued in the future. Operations are
183
183
// automatically removed after they are run or canceled.
184
- private delayedOperations : Array < DelayedOperation < AnyJs > > = [ ] ;
184
+ private delayedOperations : Array < DelayedOperation < Unknown > > = [ ] ;
185
185
186
186
// visible for testing
187
187
failure : Error ;
@@ -194,7 +194,7 @@ export class AsyncQueue {
194
194
* Adds a new operation to the queue. Returns a promise that will be resolved
195
195
* when the promise returned by the new operation is (with its value).
196
196
*/
197
- enqueue < T > ( op : ( ) => Promise < T > ) : Promise < T > {
197
+ enqueue < T extends Unknown > ( op : ( ) => Promise < T > ) : Promise < T > {
198
198
this . verifyNotFailed ( ) ;
199
199
const newTail = this . tail . then ( ( ) => {
200
200
this . operationInProgress = true ;
@@ -233,7 +233,7 @@ export class AsyncQueue {
233
233
* `delayMs` has elapsed. The returned CancelablePromise can be used to cancel
234
234
* the operation prior to its running.
235
235
*/
236
- enqueueAfterDelay < T > (
236
+ enqueueAfterDelay < T extends Unknown > (
237
237
timerId : TimerId ,
238
238
delayMs : number ,
239
239
op : ( ) => Promise < T >
@@ -247,7 +247,7 @@ export class AsyncQueue {
247
247
`Attempted to schedule multiple operations with timer id ${ timerId } .`
248
248
) ;
249
249
250
- const delayedOp = DelayedOperation . createAndSchedule (
250
+ const delayedOp = DelayedOperation . createAndSchedule < Unknown > (
251
251
this ,
252
252
timerId ,
253
253
delayMs ,
@@ -329,7 +329,7 @@ export class AsyncQueue {
329
329
}
330
330
331
331
/** Called once a DelayedOperation is run or canceled. */
332
- private removeDelayedOperation < T > ( op : DelayedOperation < T > ) : void {
332
+ private removeDelayedOperation ( op : DelayedOperation < Unknown > ) : void {
333
333
// NOTE: indexOf / slice are O(n), but delayedOperations is expected to be small.
334
334
const index = this . delayedOperations . indexOf ( op ) ;
335
335
assert ( index >= 0 , 'Delayed operation not found.' ) ;
0 commit comments