File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,8 @@ const ERROR_PROMISE_IN_SYNC = '[Quansync] Yielded an unexpected promise in sync
8
8
function isThenable < T > ( value : any ) : value is Promise < T > {
9
9
return value && typeof value === 'object' && typeof value . then === 'function'
10
10
}
11
- function isGenerator < T > ( value : any ) : value is Generator < T > {
12
- return value && typeof value === 'object' && typeof value [ Symbol . iterator ] === 'function'
13
- }
14
11
function isQuansyncGenerator < T > ( value : any ) : value is QuansyncGenerator < T > {
15
- return isGenerator ( value ) && '__quansync' in value
12
+ return value && typeof value === 'object' && typeof value [ Symbol . iterator ] === 'function' && '__quansync' in value
16
13
}
17
14
18
15
function fromObject < Return , Args extends any [ ] > (
@@ -114,7 +111,7 @@ export function quansync<Return, Args extends any[] = []>(
114
111
* Converts a promise to a Quansync generator.
115
112
*/
116
113
export function toGenerator < T > ( promise : Promise < T > | QuansyncGenerator < T > | T ) : QuansyncGenerator < T > {
117
- if ( isGenerator ( promise ) )
114
+ if ( isQuansyncGenerator ( promise ) )
118
115
return promise
119
116
return fromPromise ( promise ) ( )
120
117
}
Original file line number Diff line number Diff line change @@ -193,6 +193,18 @@ it('yield generator', async () => {
193
193
await expect ( multiply . async ( ) ) . resolves . toBe ( 'strstr' )
194
194
} )
195
195
196
+ it ( 'yield toGenerator array' , async ( ) => {
197
+ const run = quansync ( function * ( ) {
198
+ const input = [ '1' , 2 , 3 ]
199
+ const result = yield * toGenerator ( input )
200
+ expect ( result ) . toBe ( input )
201
+ return result
202
+ } )
203
+
204
+ expect ( run . sync ( ) ) . toEqual ( [ '1' , 2 , 3 ] )
205
+ await expect ( run . async ( ) ) . resolves . toEqual ( [ '1' , 2 , 3 ] )
206
+ } )
207
+
196
208
it ( 'handles tail call' , async ( ) => {
197
209
const echo = quansync ( {
198
210
sync : ( v : string ) => v ,
You can’t perform that action at this time.
0 commit comments