diff options
| author | 2022-09-30 01:04:20 -0700 | |
|---|---|---|
| committer | 2022-09-30 01:04:20 -0700 | |
| commit | 9050e6ee87ac41c08e8f23785fb73086a5ab28fd (patch) | |
| tree | b2701dfbb5d09ecd2946aad3d728663fd8ec8836 /src/napi/napi.zig | |
| parent | 84af4f0133b28813155acbab123ce957ac9e2645 (diff) | |
| download | bun-9050e6ee87ac41c08e8f23785fb73086a5ab28fd.tar.gz bun-9050e6ee87ac41c08e8f23785fb73086a5ab28fd.tar.zst bun-9050e6ee87ac41c08e8f23785fb73086a5ab28fd.zip | |
Use PollRef in napi
Diffstat (limited to '')
| -rw-r--r-- | src/napi/napi.zig | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/napi/napi.zig b/src/napi/napi.zig index a9b56ac7b..814444f0f 100644 --- a/src/napi/napi.zig +++ b/src/napi/napi.zig @@ -899,6 +899,7 @@ pub const napi_async_work = struct { can_deinit: bool = false, wait_for_deinit: bool = false, scheduled: bool = false, + ref: JSC.PollRef = .{}, pub const Status = enum(u32) { pending = 0, started = 1, @@ -942,14 +943,18 @@ pub const napi_async_work = struct { pub fn schedule(this: *napi_async_work) void { if (this.scheduled) return; this.scheduled = true; + this.ref.ref(this.global.bunVM()); WorkPool.schedule(&this.task); } pub fn cancel(this: *napi_async_work) bool { + this.ref.unref(this.global.bunVM()); return this.status.compareAndSwap(@enumToInt(Status.cancelled), @enumToInt(Status.pending), .SeqCst, .SeqCst) != null; } pub fn deinit(this: *napi_async_work) void { + this.ref.unref(this.global.bunVM()); + if (this.can_deinit) { bun.default_allocator.destroy(this); return; |
