File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -291,7 +291,7 @@ jsg::Ref<WebSocket> WebSocket::constructor(
291
291
return ws;
292
292
}
293
293
294
- kj::Promise<DeferredProxy< void > > WebSocket::couple (kj::Own<kj::WebSocket> other) {
294
+ DeferredProxyPromise< void > WebSocket::couple (kj::Own<kj::WebSocket> other) {
295
295
auto & native = *farNative;
296
296
JSG_REQUIRE (!native.state .is <AwaitingConnection>(), TypeError,
297
297
" Can't return WebSocket in a Response if it was created with `new WebSocket()`" );
@@ -333,13 +333,18 @@ kj::Promise<DeferredProxy<void>> WebSocket::couple(kj::Own<kj::WebSocket> other)
333
333
if (locality == LOCAL) {
334
334
// Since the WebSocket is terminated locally, we need the IoContext to stay live while
335
335
// it is active.
336
- co_await promise;
337
- co_return DeferredProxy<void > { kj::READY_NOW };
336
+ co_return co_await promise;
338
337
} else {
339
338
// Since the WebSocket is just proxying through, we can do the pump in a deferred proxy task.
340
339
// Note that we don't need to (and can't) register any pending events in this case since the
341
340
// IoContext is free to go away at this point.
342
- co_return DeferredProxy<void > { kj::mv (promise) };
341
+
342
+ // To begin deferred proxying, we can use this magic `KJ_CO_MAGIC` expression, which fulfills
343
+ // our outer promise for a DeferredProxy<void>, which wraps a promise for the rest of this
344
+ // coroutine.
345
+ KJ_CO_MAGIC BEGIN_DEFERRED_PROXYING;
346
+
347
+ co_return co_await promise;
343
348
}
344
349
}
345
350
Original file line number Diff line number Diff line change @@ -253,7 +253,7 @@ class WebSocket: public EventTarget {
253
253
// response once it's available. This includes assigning the native websocket and dispatching the
254
254
// relevant `open`/`error` events.
255
255
256
- kj::Promise<DeferredProxy< void > > couple (kj::Own<kj::WebSocket> other);
256
+ DeferredProxyPromise< void > couple (kj::Own<kj::WebSocket> other);
257
257
// Pumps messages from this WebSocket to `other`, and from `other` to this, making sure to
258
258
// register pending events as appropriate. Used to implement FetchEvent.respondWith().
259
259
//
You can’t perform that action at this time.
0 commit comments