Pay attention
This documentation is for the as yet unreleased version of effector Spacewatch 23.0.

allSettled

allSettled(unit, {scope, params?})

Formulae

allSettled<T>(unit: Event<T>, {scope: Scope, params?: T}): Promise<void>
allSettled<T>(unit: Effect<T, Done, Fail>, {scope: Scope, params?: T}): Promise<
  | {status: 'done'; value: Done}
  | {status: 'fail'; value: Fail}
>
allSettled<T>(unit: Store<T>, {scope: Scope, params?: T}): Promise<void>

Call the provided unit within the current scope and wait for all triggered effects to complete

Arguments

  1. unit: Event or Effect to be called
  2. scope: Scope
  3. params: params passed to unit
since

Return value for effect is supported since effector 21.4.0

Example

Contribution

Please, open PullRequest and contribute examples for this section via โ€œEdit this pageโ€ link below.

allSettled(scope)

allSettled<T>(scope): Promise<void>

Check the provided scope for any ongoing computations and wait for their completion.

Arguments

  1. scope: Scope
since

Supported since effector 22.5.0

Example

Usage in tests

For example, tests that validate the integration with an external reactive API

test('integration with externalSource', async () => {
  const scope = fork()

  const updated = createEvent()

  sample({
    clock: updated,
    target: someOtherLogicStart,
  })

  // 1. Subscribe event to external source
  const externalUpdated = scopeBind(updated, {scope})
  externalSource.listen(() => externalUpdates())

  // 2. Trigger update of external source
  externalSource.trigger()

  //3. Wait for all triggered computations in effector's scope, even though these were not triggered by effector itself
  await allSettled(scope)

  // 4. Check anything as usual
  expect(...).toBe(...)
})
Contributors