import type { TemplateResult } from 'lit'; import { isAsyncIterable, isPromise, type AsyncState } from './types'; /** * Wraps an async operation in an async generator that first yields * the `loadingContent` and then the result of the operation. */ export async function* loading( asyncOperation: AsyncState, loadingContent: TemplateResult | string = 'Loading...' ): AsyncIterable { yield loadingContent; if (isPromise(asyncOperation)) { yield await asyncOperation; } else if (isAsyncIterable(asyncOperation)) { yield* asyncOperation; } else { yield asyncOperation; } }