aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/webcore/streams.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-25 13:08:51 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-25 13:08:51 -0700
commita4d46fc7db7459e3e7e895d3013ffe65b0f0078c (patch)
tree8c6d78f3ccc127b16ff38fe098223bd9b69c2736 /src/bun.js/webcore/streams.zig
parent7ce4a4e3d3f5f06a1258eefc49ce1da166e43886 (diff)
downloadbun-a4d46fc7db7459e3e7e895d3013ffe65b0f0078c.tar.gz
bun-a4d46fc7db7459e3e7e895d3013ffe65b0f0078c.tar.zst
bun-a4d46fc7db7459e3e7e895d3013ffe65b0f0078c.zip
Diffstat (limited to 'src/bun.js/webcore/streams.zig')
-rw-r--r--src/bun.js/webcore/streams.zig30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig
index abf220ad7..23aad70ec 100644
--- a/src/bun.js/webcore/streams.zig
+++ b/src/bun.js/webcore/streams.zig
@@ -1135,13 +1135,20 @@ pub const FileSink = struct {
this.scheduled_count += 1;
}
+ pub fn unwatch(this: *FileSink) void {
+ std.debug.assert(this.scheduled_count > 0);
+ std.debug.assert(this.opened_fd != std.math.maxInt(JSC.Node.FileDescriptor));
+ _ = JSC.VirtualMachine.vm.poller.unwatch(this.opened_fd, .write, FileSink, this);
+ this.scheduled_count -= 1;
+ }
+
pub fn toJS(this: *FileSink, globalThis: *JSGlobalObject) JSValue {
return JSSink.createObject(globalThis, this);
}
pub fn onPoll(this: *FileSink, _: i64, _: u16) void {
this.scheduled_count -= 1;
- this.flush();
+ _ = this.flush();
}
pub fn write(this: *@This(), data: StreamResult) StreamResult.Writable {
@@ -3185,11 +3192,32 @@ pub const FileBlobLoader = struct {
this.pending.run();
}
+ pub fn unwatch(this: *FileBlobLoader) void {
+ std.debug.assert(this.scheduled_count > 0);
+ std.debug.assert(this.fd != std.math.maxInt(JSC.Node.FileDescriptor));
+ _ = JSC.VirtualMachine.vm.poller.unwatch(this.fd, .read, FileBlobLoader, this);
+ this.scheduled_count -= 1;
+ }
+
pub fn finalize(this: *FileBlobLoader) void {
if (this.finalized)
return;
this.finalized = true;
+ if (this.scheduled_count > 0) {
+ this.unwatch();
+ }
+
+ this.pending.result = .{ .done = {} };
+ this.pending.run();
+
+ if (this.protected_view != .zero) {
+ this.protected_view.unprotect();
+ this.protected_view = .zero;
+
+ this.buf = &.{};
+ }
+
this.maybeAutoClose();
this.store.deref();