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

Function makeTls

packages/platform/node-shared/src/NodeSocket.ts:596–636  ·  view source on GitHub ↗
(
  options: Tls.ConnectionOptions & {
    readonly openTimeout?: Duration.Input | undefined
    /**
     * Maximum chunks per pull. Defaults to 4096 unless a positive safe integer or Infinity is supplied.
     * Use Infinity for unbounded batching.
     */
    readonly chunkSize?: number | undefined
  }
)

Source from the content-addressed store, hash-verified

594 * @since 4.0.0
595 */
596export const makeTls = (
597 options: Tls.ConnectionOptions & {
598 readonly openTimeout?: Duration.Input | undefined
599 /**
600 * Maximum chunks per pull. Defaults to 4096 unless a positive safe integer or Infinity is supplied.
601 * Use Infinity for unbounded batching.
602 */
603 readonly chunkSize?: number | undefined
604 }
605): Effect.Effect<Socket.Socket> =>
606 fromDuplex(
607 Effect.contextWith((context: Context.Context<Scope.Scope>) => {
608 let conn: Tls.TLSSocket | undefined
609 let isOpen = false
610 return Effect.flatMap(
611 Scope.addFinalizer(
612 Context.get(context, Scope.Scope),
613 Effect.sync(() => {
614 if (!conn) return
615 closeSocket(conn, isOpen)
616 })
617 ),
618 () =>
619 Effect.callback<Tls.TLSSocket, Socket.SocketError, never>((resume) => {
620 conn = Tls.connect(options)
621 conn.once("secureConnect", () => {
622 isOpen = true
623 resume(Effect.succeed(conn!))
624 })
625 conn.on("error", (cause: Error) => {
626 resume(Effect.fail(
627 new Socket.SocketError({
628 reason: new Socket.SocketOpenError({ kind: "Unknown", cause })
629 })
630 ))
631 })
632 })
633 )
634 }),
635 options
636 )
637
638/**
639 * Creates a `Channel` over a TLS socket, reading arrays of `Uint8Array`

Callers 1

makeTlsChannelFunction · 0.70

Calls 11

addFinalizerMethod · 0.80
onceMethod · 0.80
fromDuplexFunction · 0.70
closeSocketFunction · 0.70
getMethod · 0.65
connectMethod · 0.65
onMethod · 0.65
failMethod · 0.65
resumeFunction · 0.50
syncMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected