MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeWebSocket

Function makeWebSocket

packages/effect/src/socket/Socket.ts:899–922  ·  view source on GitHub ↗
(url: string | Effect.Effect<string>, options?: {
  readonly openTimeout?: Duration.Input | undefined
  readonly protocols?: string | Array<string> | undefined
  readonly headers?: Readonly<Record<string, string>> | undefined
  readonly highWaterMark?: number | undefined
})

Source from the content-addressed store, hash-verified

897 * @since 4.0.0
898 */
899export const makeWebSocket = (url: string | Effect.Effect<string>, options?: {
900 readonly openTimeout?: Duration.Input | undefined
901 readonly protocols?: string | Array<string> | undefined
902 readonly headers?: Readonly<Record<string, string>> | undefined
903 readonly highWaterMark?: number | undefined
904}): Effect.Effect<Socket, never, WebSocketConstructor> =>
905 WebSocketConstructor.use((makeWs) =>
906 fromWebSocket(
907 Effect.acquireRelease(
908 (typeof url === "string" ? Effect.succeed(url) : url).pipe(
909 Effect.map((url) =>
910 makeWs(
911 url,
912 options?.headers === undefined
913 ? options?.protocols
914 : { protocols: options.protocols, headers: options.headers }
915 )
916 )
917 ),
918 (ws) => Effect.sync(() => ws.close(1000))
919 ),
920 options
921 )
922 )
923
924interface Pausable {
925 pause(): void

Callers 3

makeWebSocketChannelFunction · 0.70
OpenAiClient.tsFile · 0.50
NodeSocket.test.tsFile · 0.50

Calls 7

fromWebSocketFunction · 0.85
useMethod · 0.65
pipeMethod · 0.65
closeMethod · 0.65
succeedMethod · 0.45
mapMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected