From 04b8b17715ae35ef774109be0f2b86f9d6390792 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 24 Dec 2023 23:06:43 +1300 Subject: [PATCH] add source to SocketServer sockets (#40) --- .changeset/serious-sheep-lick.md | 5 +++++ docs/modules/Socket.ts.md | 1 + src/Socket.ts | 1 + src/SocketServer/Node.ts | 10 ++++++++-- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/serious-sheep-lick.md diff --git a/.changeset/serious-sheep-lick.md b/.changeset/serious-sheep-lick.md new file mode 100644 index 0000000..80fe292 --- /dev/null +++ b/.changeset/serious-sheep-lick.md @@ -0,0 +1,5 @@ +--- +"@effect/experimental": patch +--- + +add source to SocketServer sockets diff --git a/docs/modules/Socket.ts.md b/docs/modules/Socket.ts.md index a254869..2377bf0 100644 --- a/docs/modules/Socket.ts.md +++ b/docs/modules/Socket.ts.md @@ -171,6 +171,7 @@ export interface Socket { readonly run: Effect.Effect readonly writer: Effect.Effect Effect.Effect> readonly messages: Queue.Dequeue + readonly source?: unknown } ``` diff --git a/src/Socket.ts b/src/Socket.ts index d8de025..d5b2584 100644 --- a/src/Socket.ts +++ b/src/Socket.ts @@ -43,6 +43,7 @@ export interface Socket { readonly run: Effect.Effect readonly writer: Effect.Effect Effect.Effect> readonly messages: Queue.Dequeue + readonly source?: unknown } /** diff --git a/src/SocketServer/Node.ts b/src/SocketServer/Node.ts index 6080767..6c17a0f 100644 --- a/src/SocketServer/Node.ts +++ b/src/SocketServer/Node.ts @@ -62,7 +62,10 @@ export const make = ( }) ) ), - Effect.flatMap((socket) => Queue.offer(queue, socket)), + Effect.flatMap((socket) => { + ;(socket as any).source = conn + return Queue.offer(queue, socket) + }), Effect.runFork ) }) @@ -155,7 +158,10 @@ export const makeWebSocket = ( }) ) ), - Effect.flatMap((socket) => Queue.offer(queue, socket)), + Effect.flatMap((socket) => { + ;(socket as any).source = conn + return Queue.offer(queue, socket) + }), Effect.runFork ) })