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

Function makeWebSocket

packages/effect/src/unstable/socket/Socket.ts:581–596  ·  view source on GitHub ↗
(url: string | Effect.Effect<string>, options?: {
  readonly closeCodeIsError?: ((code: number) => boolean) | undefined
  readonly openTimeout?: Duration.Input | undefined
  readonly protocols?: string | Array<string> | undefined
})

Source from the content-addressed store, hash-verified

579 * @since 4.0.0
580 */
581export const makeWebSocket = (url: string | Effect.Effect<string>, options?: {
582 readonly closeCodeIsError?: ((code: number) => boolean) | undefined
583 readonly openTimeout?: Duration.Input | undefined
584 readonly protocols?: string | Array<string> | undefined
585}): Effect.Effect<Socket, never, WebSocketConstructor> =>
586 WebSocketConstructor.use((makeWs) =>
587 fromWebSocket(
588 Effect.acquireRelease(
589 (typeof url === "string" ? Effect.succeed(url) : url).pipe(
590 Effect.map((url) => makeWs(url, options?.protocols))
591 ),
592 (ws) => Effect.sync(() => ws.close(1000))
593 ),
594 options
595 )
596 )
597
598/**
599 * Builds a `Socket` from a scoped WebSocket acquisition effect, waiting for the

Callers 2

OpenAiClient.tsFile · 0.85
makeWebSocketChannelFunction · 0.85

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