Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/zero-node-socket-timeout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform-node-shared": patch
---

Respect zero-duration open timeouts when opening Node sockets.
2 changes: 1 addition & 1 deletion packages/platform/node-shared/src/NodeSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const fromDuplex = <RO>(
})
)
conn = yield* Scope.provide(open, scope).pipe(
options?.openTimeout ?
options?.openTimeout !== undefined ?
Effect.timeoutOrElse({
duration: options.openTimeout,
orElse: () =>
Expand Down
13 changes: 13 additions & 0 deletions packages/platform/node/test/NodeSocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ describe("Socket", () => {
assert.strictEqual(output, "HelloWorld")
}))

it.live("respects a zero open timeout", () =>
Effect.gen(function*() {
const socket = yield* NodeSocket.fromDuplex(Effect.never, { openTimeout: 0 })
const error = yield* socket.runRaw(() => {}).pipe(
Effect.flip,
Effect.timeout("1 second")
)
assert.strictEqual(error.reason._tag, "SocketOpenError")
if (error.reason._tag === "SocketOpenError") {
assert.strictEqual(error.reason.kind, "Timeout")
}
}))

describe("WebSocket", () => {
const url = `ws://localhost:1234`

Expand Down