-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathGenerator.ts
More file actions
29 lines (24 loc) · 1.07 KB
/
Generator.ts
File metadata and controls
29 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { __TS__CountVarargs } from "./CountVarargs";
import { GeneratorIterator } from "./GeneratorIterator";
import { __TS__Unpack } from "./Unpack";
function generatorIterator(this: GeneratorIterator) {
return this;
}
function generatorNext(this: GeneratorIterator, ...args: any[]) {
const co = this.____coroutine;
if (coroutine.status(co) === "dead") return { done: true };
const [status, value] = coroutine.resume(co, ...args);
if (!status) throw value;
return { value, done: coroutine.status(co) === "dead" };
}
export function __TS__Generator(this: void, fn: (this: void, ...args: any[]) => any) {
return function (this: void, ...args: any[]): GeneratorIterator {
const argsLength = __TS__CountVarargs(...args);
return {
// Using explicit this there, since we don't pass arguments after the first nil and context is likely to be nil
____coroutine: coroutine.create(() => fn(...__TS__Unpack(args, 1, argsLength))),
[Symbol.iterator]: generatorIterator,
next: generatorNext,
};
};
}