Skip to content

Commit

Permalink
Simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 7, 2023
1 parent 88fc0ca commit 5ee1f94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/run/stop/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { noUnhandledRejection } from '../../error/unhandled_rejection.js'
import { createController } from '../../utils/timeout.js'
import { addAction } from '../preview/action.js'
import { refreshPreview } from '../preview/update/main.js'

Expand All @@ -15,8 +14,14 @@ import { removeDefaultHandlers, restoreDefaultHandlers } from './signals.js'
// on how many times the benchmark was stopped/continued.
export const addStopHandler = async (previewState) => {
const signalHandler = removeDefaultHandlers()
const { cancelSignal, cancel } = createController()
const stopState = { stopped: false, signalHandler, cancelSignal, cancel }
const controller = new AbortController()
const cancel = controller.abort.bind(controller)
const stopState = {
stopped: false,
signalHandler,
cancelSignal: controller.signal,
cancel,
}
// eslint-disable-next-line fp/no-mutation
stopState.onAbort = noUnhandledRejection(handleStop(stopState, previewState))

Expand Down
8 changes: 0 additions & 8 deletions src/utils/timeout.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { pEvent } from 'p-event'

export const createController = () => {
const controller = new AbortController()
return {
cancelSignal: controller.signal,
cancel: controller.abort.bind(controller),
}
}

// TODO: replace with `once()` after dropping support for Node <15
export const waitForEvents = async (eventEmitter, signals, cancelSignal) => {
const promise = pEvent(eventEmitter, signals)
Expand Down

0 comments on commit 5ee1f94

Please sign in to comment.