refactor: don't expose the deferred (#12130)

This commit is contained in:
Nikolay Vitkov 2024-03-22 16:57:29 +01:00 committed by GitHub
parent 22a680dd09
commit 35504ae0e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,17 +31,14 @@ export class CallbackRegistry {
} catch (error) {
// We still throw sync errors synchronously and clean up the scheduled
// callback.
callback.promise
.valueOrThrow()
.catch(debugError)
.finally(() => {
this.#callbacks.delete(callback.id);
});
callback.promise.catch(debugError).finally(() => {
this.#callbacks.delete(callback.id);
});
callback.reject(error as Error);
throw error;
}
// Must only have sync code up until here.
return callback.promise.valueOrThrow().finally(() => {
return callback.promise.finally(() => {
this.#callbacks.delete(callback.id);
});
}
@ -148,8 +145,8 @@ export class Callback {
return this.#id;
}
get promise(): Deferred<unknown> {
return this.#deferred;
get promise(): Promise<unknown> {
return this.#deferred.valueOrThrow();
}
get error(): ProtocolError {