MCPcopy Create free account
hub / github.com/chainjet/platform / convertObservableToRunResponse

Function convertObservableToRunResponse

libs/common/src/utils/async.utils.ts:4–24  ·  view source on GitHub ↗
(res: RunResponse | Observable<RunResponse>)

Source from the content-addressed store, hash-verified

2import { Observable } from 'rxjs'
3
4export async function convertObservableToRunResponse(res: RunResponse | Observable<RunResponse>): Promise<RunResponse> {
5 if ('outputs' in res) {
6 return res
7 }
8 return new Promise((resolve, reject) => {
9 const items: any[] = []
10 let store: RunResponse['store']
11 res.subscribe({
12 next(item) {
13 items.push(item.outputs)
14 store = item.store
15 },
16 error(err) {
17 reject(err)
18 },
19 complete() {
20 resolve({ outputs: { items }, store })
21 },
22 })
23 })
24}
25
26export function wait(ms: number): Promise<void> {
27 return new Promise((resolve) => setTimeout(resolve, ms))

Calls 1

subscribeMethod · 0.45

Tested by

no test coverage detected