Concurrency helpers for plain createEffect with Farfetched-style cancellation semantics.
The package extracts the core mechanics behind concurrency and onAbort into a standalone library for Effector:
createConcurrentEffectapplyEffectConcurrencygetCallObjectEventonAbortabortErrorusageError
npm install @domosedov/effector-concurrent-effect effectoreffector is a peer dependency.
import { createConcurrentEffect, onAbort } from '@domosedov/effector-concurrent-effect'
const requestFx = createConcurrentEffect({
strategy: 'TAKE_LATEST',
handler: async (url: string) => {
const abortController = new AbortController()
onAbort(() => {
abortController.abort()
})
const response = await fetch(url, {
signal: abortController.signal,
})
return response.text()
},
})TAKE_EVERY: allow all calls to run.TAKE_LATEST: abort all previous pending calls when a new one starts.TAKE_FIRST: reject every next call while one is already in flight.
import { createEvent } from 'effector'
import { createConcurrentEffect } from '@domosedov/effector-concurrent-effect'
const abortAll = createEvent()
const requestFx = createConcurrentEffect({
abortAll,
handler: async () => {
// ...
},
})onAbort must be called synchronously inside the handler before the first await. The callback is invoked when the current call is aborted either manually through the call object or automatically by a concurrency strategy.
If onAbort is used outside that synchronous part of the handler, or called more than once for the same operation, the library throws a ConcurrentUsageError.
vp install
vp check
vp test run
vp packThis package uses Changesets.
vp exec changeset
vp run version
vp run releaseIf GitHub Actions is enabled, pushes to main use .github/workflows/release.yml to:
- run
vp check - run
vp test - open a release PR when new changesets are present
- publish to npm after the release PR is merged
Set the NPM_TOKEN repository secret before enabling automatic publication.