Skip to content

Commit

Permalink
Merge pull request #12 from edvansts/main
Browse files Browse the repository at this point in the history
fix: promise.withResolvers polyfill added to createCallable
  • Loading branch information
desko27 authored Aug 22, 2024
2 parents 20594ed + eb90406 commit 9213f5e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/createCallable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export function createCallable<Props = void, Response = void, RootProps = {}>(
if ($setStack === null) throw new Error('No <Root> found!')

const key = String($nextKey++)
const promise = Promise.withResolvers<Response>()
let resolve: (value: Response | PromiseLike<Response>) => void
const promise = new Promise<Response>((res) => {
resolve = res
})

const end = (response: Response) => {
promise.resolve(response)
resolve(response)
if (!$setStack) return
const scopedSetStack = $setStack

Expand All @@ -38,7 +41,7 @@ export function createCallable<Props = void, Response = void, RootProps = {}>(
}

$setStack((prev) => [...prev, { key, props, end, ended: false }])
return promise.promise
return promise
},
Root: (rootProps: RootProps) => {
const [stack, setStack] = useState<PrivateStackState<Props, Response>>([])
Expand Down

0 comments on commit 9213f5e

Please sign in to comment.