Skip to content

Commit

Permalink
Add waitUntilTasks param to CustomEvent::run().
Browse files Browse the repository at this point in the history
`JsRpcCustomEventImpl` will need this. I'm surprised it wasn't provided already.
  • Loading branch information
kentonv committed Mar 27, 2024
1 parent 7e6f215 commit d127570
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/workerd/api/hibernatable-web-socket.c++
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ jsg::Ref<WebSocket> HibernatableWebSocketEvent::claimWebSocket(jsg::Lock& lock,

kj::Promise<WorkerInterface::CustomEvent::Result> HibernatableWebSocketCustomEventImpl::run(
kj::Own<IoContext_IncomingRequest> incomingRequest,
kj::Maybe<kj::StringPtr> entrypointName) {
kj::Maybe<kj::StringPtr> entrypointName,
kj::TaskSet& waitUntilTasks) {
// Mark the request as delivered because we're about to run some JS.
auto& context = incomingRequest->getContext();
incomingRequest->delivered();
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/hibernatable-web-socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class HibernatableWebSocketCustomEventImpl final: public WorkerInterface::Custom

kj::Promise<Result> run(
kj::Own<IoContext_IncomingRequest> incomingRequest,
kj::Maybe<kj::StringPtr> entrypointName) override;
kj::Maybe<kj::StringPtr> entrypointName,
kj::TaskSet& waitUntilTasks) override;

kj::Promise<Result> sendRpc(
capnp::HttpOverCapnpFactory& httpOverCapnpFactory,
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/queue.c++
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ jsg::Ref<QueueEvent> startQueueEvent(

kj::Promise<WorkerInterface::CustomEvent::Result> QueueCustomEventImpl::run(
kj::Own<IoContext_IncomingRequest> incomingRequest,
kj::Maybe<kj::StringPtr> entrypointName) {
kj::Maybe<kj::StringPtr> entrypointName,
kj::TaskSet& waitUntilTasks) {
incomingRequest->delivered();
auto& context = incomingRequest->getContext();

Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ class QueueCustomEventImpl final: public WorkerInterface::CustomEvent, public kj

kj::Promise<Result> run(
kj::Own<IoContext_IncomingRequest> incomingRequest,
kj::Maybe<kj::StringPtr> entrypointName) override;
kj::Maybe<kj::StringPtr> entrypointName,
kj::TaskSet& waitUntilTasks) override;

kj::Promise<Result> sendRpc(
capnp::HttpOverCapnpFactory& httpOverCapnpFactory,
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/trace.c++
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ kj::Promise<void> sendTracesToExportedHandler(
} // namespace

auto TraceCustomEventImpl::run(
kj::Own<IoContext::IncomingRequest> incomingRequest, kj::Maybe<kj::StringPtr> entrypointNamePtr)
kj::Own<IoContext::IncomingRequest> incomingRequest, kj::Maybe<kj::StringPtr> entrypointNamePtr,
kj::TaskSet& waitUntilTasks)
-> kj::Promise<Result> {
// Don't bother to wait around for the handler to run, just hand it off to the waitUntil tasks.
waitUntilTasks.add(
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ class TraceCustomEventImpl final: public WorkerInterface::CustomEvent {

kj::Promise<Result> run(
kj::Own<IoContext::IncomingRequest> incomingRequest,
kj::Maybe<kj::StringPtr> entrypointName) override;
kj::Maybe<kj::StringPtr> entrypointName,
kj::TaskSet& waitUntilTasks) override;

kj::Promise<Result> sendRpc(
capnp::HttpOverCapnpFactory& httpOverCapnpFactory,
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/worker-rpc.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,8 @@ private:

kj::Promise<WorkerInterface::CustomEvent::Result> JsRpcSessionCustomEventImpl::run(
kj::Own<IoContext::IncomingRequest> incomingRequest,
kj::Maybe<kj::StringPtr> entrypointName) {
kj::Maybe<kj::StringPtr> entrypointName,
kj::TaskSet& waitUntilTasks) {
IoContext& ioctx = incomingRequest->getContext();

incomingRequest->delivered();
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/worker-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ class JsRpcSessionCustomEventImpl final: public WorkerInterface::CustomEvent {

kj::Promise<Result> run(
kj::Own<IoContext::IncomingRequest> incomingRequest,
kj::Maybe<kj::StringPtr> entrypointName) override;
kj::Maybe<kj::StringPtr> entrypointName,
kj::TaskSet& waitUntilTasks) override;

kj::Promise<Result> sendRpc(
capnp::HttpOverCapnpFactory& httpOverCapnpFactory,
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/io/worker-entrypoint.c++
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,8 @@ kj::Promise<WorkerInterface::CustomEvent::Result>
this->incomingRequest = kj::none;

auto& context = incomingRequest->getContext();
auto promise = event->run(kj::mv(incomingRequest), entrypointName).attach(kj::mv(event));
auto promise = event->run(kj::mv(incomingRequest), entrypointName, waitUntilTasks)
.attach(kj::mv(event));

// TODO(cleanup): In theory `context` may have been destroyed by now if `event->run()` dropped
// the `incomingRequest` synchronously. No current implementation does that, and
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/io/worker-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class WorkerInterface: public kj::HttpService {
// for this event.
virtual kj::Promise<Result> run(
kj::Own<IoContext_IncomingRequest> incomingRequest,
kj::Maybe<kj::StringPtr> entrypointName) = 0;
kj::Maybe<kj::StringPtr> entrypointName,
kj::TaskSet& waitUntilTasks) = 0;

// Forward the event over RPC.
virtual kj::Promise<Result> sendRpc(
Expand Down

0 comments on commit d127570

Please sign in to comment.