mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 20:59:10 +00:00
use Object instead of Map for promise table (#4309)
This commit is contained in:
parent
68119e1d7e
commit
dca00211ab
2 changed files with 15 additions and 8 deletions
|
@ -19,7 +19,10 @@ interface JsonResponse {
|
|||
promiseId?: number; // Only present in async messages.
|
||||
}
|
||||
|
||||
const promiseTable = new Map<number, util.Resolvable<JsonResponse>>();
|
||||
// Using an object without a prototype because `Map` was causing GC problems.
|
||||
const promiseTable: {
|
||||
[key: number]: util.Resolvable<JsonResponse>;
|
||||
} = Object.create(null);
|
||||
let _nextPromiseId = 1;
|
||||
|
||||
function nextPromiseId(): number {
|
||||
|
@ -48,9 +51,9 @@ export function asyncMsgFromRust(resUi8: Uint8Array): void {
|
|||
const res = decode(resUi8);
|
||||
util.assert(res.promiseId != null);
|
||||
|
||||
const promise = promiseTable.get(res.promiseId!);
|
||||
const promise = promiseTable[res.promiseId!];
|
||||
util.assert(promise != null);
|
||||
promiseTable.delete(res.promiseId!);
|
||||
delete promiseTable[res.promiseId!];
|
||||
promise.resolve(res);
|
||||
}
|
||||
|
||||
|
@ -89,7 +92,7 @@ export async function sendAsync(
|
|||
promise.resolve(res);
|
||||
} else {
|
||||
// Async result.
|
||||
promiseTable.set(promiseId, promise);
|
||||
promiseTable[promiseId] = promise;
|
||||
}
|
||||
|
||||
const res = await promise;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue