diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2023-02-22 21:09:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 19:09:59 +0000 |
commit | 0f9daaeacb402a7199e58b14ad01ec0091ac2c8d (patch) | |
tree | 0c5269bb8b7b4905e4cb1e4ade61149767479abf /test_ffi/tests/event_loop_integration.ts | |
parent | 9b8992d4b4acb3a54ca7d988d181a266841013d9 (diff) |
fix(ext/ffi): Fix re-ref'ing UnsafeCallback (#17704)
Diffstat (limited to 'test_ffi/tests/event_loop_integration.ts')
-rw-r--r-- | test_ffi/tests/event_loop_integration.ts | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/test_ffi/tests/event_loop_integration.ts b/test_ffi/tests/event_loop_integration.ts index e44c66ab6..28152dabf 100644 --- a/test_ffi/tests/event_loop_integration.ts +++ b/test_ffi/tests/event_loop_integration.ts @@ -26,6 +26,7 @@ const dylib = Deno.dlopen( } as const, ); +let retry = false; const tripleLogCallback = () => { console.log("Sync"); Promise.resolve().then(() => { @@ -35,10 +36,18 @@ const tripleLogCallback = () => { setTimeout(() => { console.log("Timeout"); callback.unref(); + + if (retry) { + // Re-ref and retry the call to make sure re-refing works. + console.log("RETRY THREAD SAFE"); + retry = false; + callback.ref(); + dylib.symbols.call_stored_function_thread_safe_and_log(); + } }, 10); }; -const callback = new Deno.UnsafeCallback( +const callback = Deno.UnsafeCallback.threadSafe( { parameters: [], result: "void", @@ -57,10 +66,11 @@ console.log("STORED_FUNCTION called"); // Wait to make sure synch logging and async logging await new Promise((res) => setTimeout(res, 100)); -// Ref twice to make sure both `Promise.resolve().then()` and `setTimeout()` -// must resolve before isolate exists. -callback.ref(); +// Ref once to make sure both `Promise.resolve().then()` and `setTimeout()` +// must resolve and unref before isolate exists. +// One ref'ing has been done by `threadSafe` constructor. callback.ref(); console.log("THREAD SAFE"); +retry = true; dylib.symbols.call_stored_function_thread_safe_and_log(); |