You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Task will stop after ~1 second instead of running for 10 seconds
196
+
```
197
+
198
+
### Abort Events
199
+
200
+
Both `Bench` and `Task` emit `abort` events when aborted:
201
+
202
+
```ts
203
+
const controller =newAbortController()
204
+
const bench =newBench()
205
+
206
+
bench.add('task', () => {
207
+
// Task function
208
+
}, { signal: controller.signal })
209
+
210
+
const task =bench.getTask('task')
211
+
212
+
// Listen for abort events
213
+
task.addEventListener('abort', () => {
214
+
console.log('Task aborted!')
215
+
})
216
+
217
+
bench.addEventListener('abort', () => {
218
+
console.log('Bench received abort event!')
219
+
})
220
+
221
+
controller.abort()
222
+
awaitbench.run()
223
+
```
224
+
225
+
**Note:** When a task is aborted, `task.result.aborted` will be `true`, and the task will have completed any iterations that were running when the abort signal was received.
0 commit comments