Files
upstream-mirror 3a013ccdfe
Some checks failed
autofix.ci / autofix (push) Failing after 4s
Release / Release (push) Has been skipped
GitHub Actions Security Analysis / Run zizmor (push) Failing after 2s
snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:13:08 +05:00

34 lines
703 B
TypeScript

export function ref<T>(initial: T) {
let value = $state(initial)
return {
get value() {
return value
},
set value(newValue) {
value = newValue
},
}
}
export function promiseWithResolvers<T>() {
let resolve: (value: T) => void
let reject: (reason?: any) => void
const promise = new Promise<T>((res, rej) => {
resolve = res
reject = rej
})
return { promise, resolve: resolve!, reject: reject! }
}
export function withEffectRoot(fn: () => void | Promise<void>) {
return async () => {
let promise: void | Promise<void> = Promise.resolve()
const cleanup = $effect.root(() => {
promise = fn()
})
await promise
cleanup()
}
}