MCPcopy
hub / github.com/nodejs/undici / add

Method add

lib/web/websocket/sender.js:32–74  ·  view source on GitHub ↗
(item, cb, hint)

Source from the content-addressed store, hash-verified

30 }
31
32 add (item, cb, hint) {
33 if (hint !== sendHints.blob) {
34 if (!this.#running) {
35 // TODO(@tsctx): support fast-path for string on running
36 if (hint === sendHints.text) {
37 // special fast-path for string
38 const { 0: head, 1: body } = WebsocketFrameSend.createFastTextFrame(item)
39 this.#socket.cork()
40 this.#socket.write(head)
41 this.#socket.write(body, cb)
42 this.#socket.uncork()
43 } else {
44 // direct writing
45 this.#socket.write(createFrame(item, hint), cb)
46 }
47 } else {
48 /** @type {SendQueueNode} */
49 const node = {
50 promise: null,
51 callback: cb,
52 frame: createFrame(item, hint)
53 }
54 this.#queue.push(node)
55 }
56 return
57 }
58
59 /** @type {SendQueueNode} */
60 const node = {
61 promise: item.arrayBuffer().then((ab) => {
62 node.promise = null
63 node.frame = createFrame(ab, hint)
64 }),
65 callback: cb,
66 frame: null
67 }
68
69 this.#queue.push(node)
70
71 if (!this.#running) {
72 this.#run()
73 }
74 }
75
76 async #run () {
77 this.#running = true

Callers

nothing calls this directly

Calls 8

#runMethod · 0.95
createFrameFunction · 0.85
createFastTextFrameMethod · 0.80
corkMethod · 0.80
uncorkMethod · 0.80
arrayBufferMethod · 0.65
writeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected