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

Function writeAll

packages/platform/node-shared/src/NodeSocket.ts:499–528  ·  view source on GitHub ↗
(
      chunks: Arr.NonEmptyReadonlyArray<Uint8Array | string>
    )

Source from the content-addressed store, hash-verified

497 })
498
499 const writeAll = (
500 chunks: Arr.NonEmptyReadonlyArray<Uint8Array | string>
501 ): Effect.Effect<void, Socket.SocketError> =>
502 Effect.suspend(() => {
503 if (terminalError !== undefined) return Effect.fail(terminalError)
504 const conn = currentSocket
505 if (conn === undefined) return latch.whenOpen(writeAll(chunks))
506 let needsDrain = false
507 try {
508 if (chunks.length === 1) {
509 needsDrain = !conn.write(chunks[0])
510 } else {
511 conn.cork()
512 try {
513 for (let i = 0; i < chunks.length; i++) {
514 needsDrain = !conn.write(chunks[i]) || needsDrain
515 }
516 } finally {
517 conn.uncork()
518 }
519 }
520 } catch (cause) {
521 return Effect.fail(
522 new Socket.SocketError({
523 reason: new Socket.SocketWriteError({ cause })
524 })
525 )
526 }
527 return needsDrain ? awaitDrain(conn) : Effect.void
528 })
529
530 const writer: Socket.Socket["writer"] = Effect.acquireRelease(
531 Effect.succeed({ write, writeAll }),

Callers

nothing calls this directly

Calls 4

awaitDrainFunction · 0.85
whenOpenMethod · 0.80
failMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected