Skip to content

Commit 2393224

Browse files
committed
fix: support getIsAsync for macro
1 parent f31b2c2 commit 2393224

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export function toGenerator<T>(promise: Promise<T> | QuansyncGenerator<T> | T):
142142
/**
143143
* @returns `true` if the current context is async, `false` otherwise.
144144
*/
145-
export function* getIsAsync(): Generator<typeof GET_IS_ASYNC, boolean, unknown> {
146-
return !!(yield GET_IS_ASYNC)
147-
}
145+
export const getIsAsync = quansync({
146+
async: () => Promise.resolve(true),
147+
sync: () => false,
148+
})

test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ it('call onYield hook', async () => {
285285

286286
it('getIsAsync', async () => {
287287
const fn = quansync(function* () {
288-
const isAsync: boolean = yield* getIsAsync()
288+
const isAsync = (yield getIsAsync()) as boolean
289289
return isAsync
290290
})
291291
await expect(fn.async()).resolves.toBe(true)

0 commit comments

Comments
 (0)