MCPcopy Index your code
hub / github.com/anomalyco/opencode / firstEvent

Function firstEvent

packages/opencode/test/server/httpapi-sdk.test.ts:142–164  ·  view source on GitHub ↗
(open: (signal: AbortSignal) => Promise<{ stream: AsyncIterator<unknown> }>)

Source from the content-addressed store, hash-verified

140}
141
142function firstEvent(open: (signal: AbortSignal) => Promise<{ stream: AsyncIterator<unknown> }>) {
143 return Effect.acquireRelease(
144 Effect.sync(() => new AbortController()),
145 (controller) => Effect.sync(() => controller.abort()),
146 ).pipe(
147 Effect.flatMap((controller) =>
148 Effect.acquireRelease(
149 call(() => open(controller.signal)),
150 (events) => call(async () => void (await events.stream.return?.(undefined))).pipe(Effect.ignore),
151 ).pipe(
152 Effect.flatMap((events) =>
153 call(() => events.stream.next()).pipe(
154 Effect.timeoutOrElse({
155 duration: "1 second",
156 orElse: () => Effect.fail(new Error("timed out waiting for SDK event")),
157 }),
158 ),
159 ),
160 Effect.map((result) => result.value),
161 ),
162 ),
163 )
164}
165
166function record(value: unknown) {
167 return value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value)) : {}

Callers 1

Calls 5

syncMethod · 0.80
callFunction · 0.70
openFunction · 0.50
abortMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected