mirror of
https://github.com/denoland/deno.git
synced 2025-10-03 15:44:36 +00:00
refactor: replace deferred()
from std/async
with Promise.withResolvers()
(#21234)
Closes #21041 --------- Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
parent
0ffcb46e0f
commit
616354e76c
35 changed files with 952 additions and 1020 deletions
|
@ -482,30 +482,12 @@ function test_fill_buffer(fillValue, arr) {
|
|||
test_fill_buffer(0, [2, 3, 4]);
|
||||
test_fill_buffer(5, [2, 7, 3, 2, 1]);
|
||||
|
||||
// Test non blocking calls
|
||||
|
||||
function deferred() {
|
||||
let methods;
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
methods = {
|
||||
async resolve(value) {
|
||||
await value;
|
||||
resolve(value);
|
||||
},
|
||||
reject(reason) {
|
||||
reject(reason);
|
||||
},
|
||||
};
|
||||
});
|
||||
return Object.assign(promise, methods);
|
||||
}
|
||||
|
||||
const promise = deferred();
|
||||
const deferred = Promise.withResolvers();
|
||||
const buffer3 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
dylib.symbols.nonblocking_buffer(buffer3, buffer3.length).then(() => {
|
||||
promise.resolve();
|
||||
deferred.resolve();
|
||||
});
|
||||
await promise;
|
||||
await deferred.promise;
|
||||
|
||||
let start = performance.now();
|
||||
dylib.symbols.sleep_blocking(100);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue