( iterations: LoopCallback | number, factory?: LoopCallback, )
| 90 | factory: LoopCallback, |
| 91 | ): ThreadGenerator; |
| 92 | export function* loop( |
| 93 | iterations: LoopCallback | number, |
| 94 | factory?: LoopCallback, |
| 95 | ): ThreadGenerator { |
| 96 | if (typeof iterations !== 'number') { |
| 97 | factory = iterations; |
| 98 | iterations = Infinity; |
| 99 | } |
| 100 | |
| 101 | if (iterations === Infinity && useThread().parent === null) { |
| 102 | useLogger().error({ |
| 103 | message: 'Tried to execute an infinite loop in the main thread.', |
| 104 | remarks: infiniteLoop, |
| 105 | stack: new Error().stack, |
| 106 | }); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | for (let i = 0; i < iterations; i++) { |
| 111 | const generator = factory!(i); |
| 112 | if (generator) { |
| 113 | yield* generator; |
| 114 | } else { |
| 115 | yield; |
| 116 | } |
| 117 | } |
| 118 | } |
no test coverage detected