@@ -1137,14 +1137,34 @@ pub const Transport = struct {
11371137 }
11381138 };
11391139
1140+ /// Consider using `readJsonMessageUncancelable` to avoid `error.Canceled` being returned.
11401141 pub fn readJsonMessage (transport : * Transport , io : std.Io , allocator : std.mem.Allocator ) ReadError ! []u8 {
11411142 return try transport .vtable .readJsonMessage (transport , io , allocator );
11421143 }
11431144
1145+ pub fn readJsonMessageUncancelable (transport : * Transport , io : std.Io , allocator : std.mem.Allocator ) ! void {
1146+ const old_cancel_protect = io .swapCancelProtection (.blocked );
1147+ defer _ = io .swapCancelProtection (old_cancel_protect );
1148+ return Transport .readJsonMessage (transport , io , allocator ) catch | err | switch (err ) {
1149+ error .Canceled = > unreachable ,
1150+ else = > | e | return e ,
1151+ };
1152+ }
1153+
1154+ /// Consider using `writeJsonMessageUncancelable` to avoid `error.Canceled` being returned.
11441155 pub fn writeJsonMessage (transport : * Transport , io : std.Io , json_message : []const u8 ) WriteError ! void {
11451156 return try transport .vtable .writeJsonMessage (transport , io , json_message );
11461157 }
11471158
1159+ pub fn writeJsonMessageUncancelable (transport : * Transport , io : std.Io , json_message : []const u8 ) ! void {
1160+ const old_cancel_protect = io .swapCancelProtection (.blocked );
1161+ defer _ = io .swapCancelProtection (old_cancel_protect );
1162+ Transport .writeJsonMessage (transport , io , json_message ) catch | err | switch (err ) {
1163+ error .Canceled = > unreachable ,
1164+ else = > | e | return e ,
1165+ };
1166+ }
1167+
11481168 pub fn writeRequest (
11491169 transport : * Transport ,
11501170 allocator : std.mem.Allocator ,
0 commit comments