MCPcopy
hub / github.com/vitest-dev/vitest / receive

Function receive

test/browser/specs/inspect.test.ts:62–84  ·  view source on GitHub ↗
(methodOrId?: string | { id: number })

Source from the content-addressed store, hash-verified

60 }
61
62 async function receive(methodOrId?: string | { id: number }): Promise<Message> {
63 const { promise, resolve, reject } = withResolvers()
64 listeners.push(listener)
65 ws.onerror = reject
66
67 function listener(message) {
68 const filter = typeof methodOrId === 'string' ? { method: methodOrId } : { id: methodOrId.id }
69
70 const methodMatch = message.method && message.method === filter.method
71 const idMatch = message.id && message.id === filter.id
72
73 if (methodMatch || idMatch) {
74 resolve(message)
75 listeners = listeners.filter(l => l !== listener)
76 ws.onerror = undefined
77 }
78 else if (!filter.id && !filter.method) {
79 resolve(message)
80 }
81 }
82
83 return promise
84 }
85
86 async function send(message: Message): Promise<any> {
87 const currentId = id++

Callers 2

inspect.test.tsFile · 0.70
sendFunction · 0.70

Calls 1

withResolversFunction · 0.70

Tested by

no test coverage detected