How to use @redux-saga/delay-p - 4 common examples

To help you get started, we’ve selected a few @redux-saga/delay-p examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github redux-saga / redux-saga / packages / core / __tests__ / sagaHelpers / throttle.js View on Github external
function* root() {
    const task = yield throttle(100, 'ACTION', worker, 'a1', 'a2')
    yield take('CANCEL_WATCHER')
    yield cancel(task)
  }

  function* worker(arg1, arg2, { payload }) {
    actual.push([arg1, arg2, payload])
  }

  const dispatchedActions = []

  for (let i = 0; i < 35; i++) {
    dispatchedActions.push(
      delayP(i * 10)
        .then(() => store.dispatch({ type: 'ACTION', payload: i }))
        .then(() => jest.advanceTimersByTime(10)), // next tick
    )
  }

  Promise.resolve()
    .then(() => jest.advanceTimersByTime(1)) // just start for the smallest tick
    .then(() => jest.advanceTimersByTime(10)) // tick past first delay

  return (
    dispatchedActions[34] // wait so trailing dispatch gets processed
      .then(() => jest.advanceTimersByTime(100))
      .then(() => store.dispatch({ type: 'CANCEL_WATCHER' }))
      // shouldn't be processed cause of getting canceled
      .then(() => store.dispatch({ type: 'ACTION', payload: 40 }))
      .then(() => {
github redux-saga / redux-saga / packages / core / __tests__ / sagaHelpers / delay.js View on Github external
test('delay', async () => {
  const actual = []
  const myVal = 'myValue'
  const expected = [true, myVal]
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  middleware.run(saga)

  function* saga() {
    actual.push(yield delay(1))
    actual.push(yield delay(1, myVal))
  }

  await delayP(100)

  expect(actual).toEqual(expected)
})
github pekkis / hardcore-react-training / client / src / sagas / notification.js View on Github external
export function* autoDismissal(id, timeout = 7000) {
  yield delay(timeout);
  yield call(dismissNotification, id);
}

@redux-saga/delay-p

Promisified setTimeout

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis

Popular @redux-saga/delay-p functions