diff --git a/src/bun.js/bindings/webcore/MessagePort.cpp b/src/bun.js/bindings/webcore/MessagePort.cpp index 7cda23e66b..da05e61bd7 100644 --- a/src/bun.js/bindings/webcore/MessagePort.cpp +++ b/src/bun.js/bindings/webcore/MessagePort.cpp @@ -185,7 +185,7 @@ ExceptionOr MessagePort::postMessage(JSC::JSGlobalObject& state, JSC::JSVa auto* context = scriptExecutionContext(); if (!context->canSendMessage()) { - context->postImmediateCppTask([protectedThis = Ref { *this }, message = WTFMove(message)](ScriptExecutionContext& ctx) mutable { + context->postTask([protectedThis = Ref { *this }, message = WTFMove(message)](ScriptExecutionContext& ctx) mutable { if (protectedThis->isEntangled()) { MessagePortChannelProvider::fromContext(ctx).postMessageToRemote(WTFMove(message), protectedThis->m_remoteIdentifier); } @@ -289,7 +289,7 @@ void MessagePort::processMessages(ScriptExecutionContext& context, Vector contextPtr = protectedThis->scriptExecutionContext(); if (!contextPtr || contextPtr->activeDOMObjectsAreSuspended() || !protectedThis->isEntangled()) { diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index c6a3c1099e..80259c212f 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -479,7 +479,6 @@ pub fn tick(this: *EventLoop) void { while (true) { while (this.tickWithCount(ctx) > 0) : (this.global.handleRejectedPromises()) { this.tickConcurrent(); - this.tickImmediateTasks(ctx); } else { this.drainMicrotasksWithGlobal(global, global_vm) catch return; if (scope.hasException()) return; diff --git a/test/js/web/workers/message-port-lifecycle.test.ts b/test/js/web/workers/message-port-lifecycle.test.ts index 4b85053e85..34923e453f 100644 --- a/test/js/web/workers/message-port-lifecycle.test.ts +++ b/test/js/web/workers/message-port-lifecycle.test.ts @@ -2,7 +2,7 @@ import assert from "node:assert"; import { test } from "node:test"; import { MessageChannel, receiveMessageOnPort, Worker } from "worker_threads"; -test("MessagePort postMessage uses immediate C++ tasks correctly", async () => { +test("MessagePort postMessage respects event loop timing", async () => { const { port1, port2 } = new MessageChannel(); const messages: string[] = []; @@ -90,7 +90,7 @@ test("MessagePort messages execute after process.nextTick (Node.js compatibility port2.close(); }); -test("MessagePort immediate C++ tasks work with workers", async () => { +test("MessagePort message delivery works with workers", async () => { const worker = new Worker( ` const { parentPort, MessageChannel } = require('worker_threads'); @@ -169,7 +169,7 @@ test("MessagePort immediate C++ tasks work with workers", async () => { worker.terminate(); }); -test("immediate C++ tasks don't starve microtasks", async () => { +test("MessagePort messages don't starve microtasks", async () => { const { port1, port2 } = new MessageChannel(); const executionOrder: string[] = []; @@ -252,7 +252,7 @@ test("high volume MessagePort operations maintain order", async () => { port2.close(); }); -test("MessagePort close behavior with immediate C++ tasks", async () => { +test("MessagePort close behavior during message handling", async () => { const { port1, port2 } = new MessageChannel(); let messageReceived = false; @@ -286,7 +286,7 @@ test("MessagePort close behavior with immediate C++ tasks", async () => { port1.close(); }); -test("receiveMessageOnPort works with immediate C++ tasks", () => { +test("receiveMessageOnPort synchronous message retrieval", () => { const { port1, port2 } = new MessageChannel(); port1.postMessage("msg1");