Skip to content

Commit d71047b

Browse files
committed
refactor: re-organize
1 parent 99daf3b commit d71047b

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
"json",
3535
"jsonc",
3636
"yaml"
37+
],
38+
"cSpell.words": [
39+
"quansync"
3740
]
3841
}

src/index.ts

+2-30
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,6 @@
1-
export interface QuansyncInputObject<Return, Args extends any[]> {
2-
name?: string
3-
sync: (...args: Args) => Return
4-
async: (...args: Args) => Promise<Return>
5-
}
6-
7-
export type QuansyncGeneratorFn<Return, Args extends any[]>
8-
= ((...args: Args) => QuansyncGenerator<Return>)
9-
10-
export type QuansyncInput<Return, Args extends any[]> =
11-
| QuansyncInputObject<Return, Args>
12-
| QuansyncGeneratorFn<Return, Args>
13-
14-
export type QuansyncGenerator<Return = any, Yield = unknown> =
15-
Generator<Yield, Return, Awaited<Yield>> & { __quansync?: true }
16-
17-
export type QuansyncAwaitableGenerator<Return = any, Yield = unknown> =
18-
QuansyncGenerator<Return, Yield> & Promise<Return>
19-
20-
/**
21-
* "Superposition" function that can be consumed in both sync and async contexts.
22-
*/
23-
export type QuansyncFn<Return = any, Args extends any[] = []> =
24-
((...args: Args) => QuansyncAwaitableGenerator<Return>)
25-
& {
26-
sync: (...args: Args) => Return
27-
async: (...args: Args) => Promise<Return>
28-
}
1+
import type { QuansyncAwaitableGenerator, QuansyncFn, QuansyncGenerator, QuansyncGeneratorFn, QuansyncInput, QuansyncInputObject } from './types'
292

3+
export const GET_IS_ASYNC = Symbol.for('quansync.getIsAsync')
304
const ERROR_PROMISE_IN_SYNC = '[Quansync] Yielded an unexpected promise in sync context'
315

326
function isThenable<T>(value: any): value is Promise<T> {
@@ -39,8 +13,6 @@ function isQuansyncGenerator<T>(value: any): value is QuansyncGenerator<T> {
3913
return isGenerator(value) && '__quansync' in value
4014
}
4115

42-
export const GET_IS_ASYNC = Symbol.for('quansync.getIsAsync')
43-
4416
function fromObject<Return, Args extends any[]>(
4517
options: QuansyncInputObject<Return, Args>,
4618
): QuansyncFn<Return, Args> {

src/macro.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { QuansyncFn, QuansyncInput } from './index'
1+
import type { QuansyncFn, QuansyncInput } from './types'
22
import { quansync as _quansync } from './index'
33

44
/**

src/types.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export interface QuansyncInputObject<Return, Args extends any[]> {
2+
name?: string
3+
sync: (...args: Args) => Return
4+
async: (...args: Args) => Promise<Return>
5+
}
6+
7+
export type QuansyncGeneratorFn<Return, Args extends any[]>
8+
= ((...args: Args) => QuansyncGenerator<Return>)
9+
10+
export type QuansyncInput<Return, Args extends any[]> =
11+
| QuansyncInputObject<Return, Args>
12+
| QuansyncGeneratorFn<Return, Args>
13+
14+
export type QuansyncGenerator<Return = any, Yield = unknown> =
15+
Generator<Yield, Return, Awaited<Yield>> & { __quansync?: true }
16+
17+
export type QuansyncAwaitableGenerator<Return = any, Yield = unknown> =
18+
QuansyncGenerator<Return, Yield> & Promise<Return>
19+
20+
/**
21+
* "Superposition" function that can be consumed in both sync and async contexts.
22+
*/
23+
export type QuansyncFn<Return = any, Args extends any[] = []> =
24+
((...args: Args) => QuansyncAwaitableGenerator<Return>)
25+
& {
26+
sync: (...args: Args) => Return
27+
async: (...args: Args) => Promise<Return>
28+
}

0 commit comments

Comments
 (0)