mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix tsfn finalizers
This commit is contained in:
@@ -1258,8 +1258,8 @@ pub const EventLoop = struct {
|
||||
}
|
||||
|
||||
pub fn tickImmediateTasks(this: *EventLoop, virtual_machine: *VirtualMachine) void {
|
||||
JSC.napi.Finalizer.drain(&this.napi_finalizer_queue, this.global);
|
||||
_ = this.tickQueueWithCount(virtual_machine, "immediate_tasks");
|
||||
JSC.napi.Finalizer.drain(&this.napi_finalizer_queue, this.global);
|
||||
}
|
||||
|
||||
fn tickConcurrent(this: *EventLoop) void {
|
||||
|
||||
@@ -1480,6 +1480,8 @@ pub const Finalizer = struct {
|
||||
|
||||
pub fn drain(this: *Finalizer.Queue, env: napi_env) void {
|
||||
while (this.readItem()) |*finalizer| {
|
||||
const handle_scope = NapiHandleScope.open(env, false);
|
||||
defer if (handle_scope) |scope| scope.close(env);
|
||||
finalizer.fun.?(env, finalizer.data, finalizer.hint);
|
||||
}
|
||||
}
|
||||
@@ -1642,7 +1644,7 @@ pub const ThreadSafeFunction = struct {
|
||||
this.unref();
|
||||
|
||||
if (this.finalizer.fun) |fun| {
|
||||
fun(this.event_loop.global, this.finalizer.data, this.ctx);
|
||||
Finalizer.napi_enqueue_finalizer(fun, this.finalizer.data, this.ctx);
|
||||
}
|
||||
|
||||
if (this.callback == .js) {
|
||||
|
||||
Reference in New Issue
Block a user