MCPcopy
hub / github.com/vitest-dev/vitest / cancel

Method cancel

packages/vitest/src/node/pools/pool.ts:188–216  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

186 }
187
188 async cancel(): Promise<void> {
189 // Force exit if previous cancel is still on-going
190 // for example when user does 'CTRL+c' twice in row
191 const force = this._isCancelling
192
193 // Set flag to prevent new tasks from being queued
194 this._isCancelling = true
195
196 const pendingTasks = this.queue.splice(0)
197
198 if (pendingTasks.length) {
199 const error = new Error('Cancelled')
200 pendingTasks.forEach(task => task.resolver.reject(error))
201 }
202
203 await Promise.all(this.activeTasks.map(task => task.cancelTask({ force })))
204 this.activeTasks = []
205
206 await Promise.all(this.sharedRunners.map(runner => runner.stop()))
207 this.sharedRunners = []
208
209 await Promise.all(this.exitPromises)
210 this.exitPromises = []
211
212 this.workerIds.forEach((_, id) => this.freeWorkerId(id))
213
214 // Reset flag after cancellation completes
215 this._isCancelling = false
216 }
217
218 async close(): Promise<void> {
219 await this.cancel()

Callers 4

closeMethod · 0.95
BrowserTestRunnerClass · 0.45
initiateRunnerFunction · 0.45
executeTestsFunction · 0.45

Calls 5

freeWorkerIdMethod · 0.95
allMethod · 0.80
cancelTaskMethod · 0.80
rejectMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected