Add a few thunk utils
This commit is contained in:
@@ -66,6 +66,9 @@ export type MergedThunk = {
|
||||
status: Readable<ThunkStatusByUrl>
|
||||
}
|
||||
|
||||
export const isMergedThunk = (thunk: Thunk | MergedThunk): thunk is MergedThunk =>
|
||||
Boolean((thunk as any).thunks)
|
||||
|
||||
export const mergeThunks = (thunks: Thunk[]) => {
|
||||
const controller = new AbortController()
|
||||
|
||||
@@ -101,6 +104,16 @@ export const mergeThunks = (thunks: Thunk[]) => {
|
||||
}
|
||||
}
|
||||
|
||||
export function* walkThunks(thunks: (Thunk | MergedThunk)[]): Iterable<Thunk> {
|
||||
for (const thunk of thunks) {
|
||||
if (isMergedThunk(thunk)) {
|
||||
yield* walkThunks(thunk.thunks)
|
||||
} else {
|
||||
yield thunk
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const thunks = writable<Record<string, Thunk | MergedThunk>>({})
|
||||
|
||||
export const publishThunk = (request: ThunkRequest) => {
|
||||
@@ -208,3 +221,4 @@ thunkWorker.addGlobalHandler((thunk: Thunk) => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user