How to use the @redux-saga/deferred.arrayOfDeferred function in @redux-saga/deferred

To help you get started, we’ve selected a few @redux-saga/deferred 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__ / interpreter / cancellation.js View on Github external
test('saga cancellation: nested forked task cancellation', () => {
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let start = deferred(),
    stop = deferred(),
    subtaskDefs = arrayOfDeferred(2),
    nestedTaskDefs = arrayOfDeferred(2)
  Promise.resolve(1)
    .then(() => start.resolve('start'))
    .then(() => subtaskDefs[0].resolve('subtask_1'))
    .then(() => nestedTaskDefs[0].resolve('nested_task_1'))
    .then(() => stop.resolve('stop')) //
    .then(() => nestedTaskDefs[1].resolve('nested_task_2'))
    .then(() => subtaskDefs[1].resolve('subtask_2'))

  function* nestedTask() {
    try {
      actual.push(yield nestedTaskDefs[0].promise)
      actual.push(yield nestedTaskDefs[1].promise)
    } finally {
      if (yield io.cancelled()) actual.push(yield 'nested task cancelled')
    }
  }
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('saga cancellation: race effect', () => {
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let startDef = deferred()
  let cancelDef = deferred()
  let subroutineDefs = arrayOfDeferred(2)
  Promise.resolve(1)
    .then(() => startDef.resolve('start'))
    .then(() => cancelDef.resolve('cancel'))
    .then(() => subroutineDefs[0].resolve('subroutine 1'))
    .then(() => subroutineDefs[1].resolve('subroutine 2'))

  function* main() {
    actual.push(yield startDef.promise)

    try {
      actual.push(
        yield io.race({
          subroutine1: io.call(subroutine1),
          subroutine2: io.call(subroutine2),
        }),
      )
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('saga cancellation: nested task cancellation', () => {
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let start = deferred(),
    stop = deferred(),
    subtaskDefs = arrayOfDeferred(2),
    nestedTask1Defs = arrayOfDeferred(2),
    nestedTask2Defs = arrayOfDeferred(2)
  Promise.resolve(1)
    .then(() => start.resolve('start'))
    .then(() => subtaskDefs[0].resolve('subtask_1'))
    .then(() => nestedTask1Defs[0].resolve('nested_task_1_1'))
    .then(() => nestedTask2Defs[0].resolve('nested_task_2_1'))
    .then(() => stop.resolve('stop'))
    .then(() => nestedTask1Defs[1].resolve('nested_task_1_2'))
    .then(() => nestedTask2Defs[1].resolve('nested_task_2_2'))
    .then(() => subtaskDefs[1].resolve('subtask_2'))

  function* nestedTask1() {
    try {
      actual.push(yield nestedTask1Defs[0].promise)
      actual.push(yield nestedTask1Defs[1].promise)
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('saga cancellation: nested task cancellation', () => {
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let start = deferred(),
    stop = deferred(),
    subtaskDefs = arrayOfDeferred(2),
    nestedTask1Defs = arrayOfDeferred(2),
    nestedTask2Defs = arrayOfDeferred(2)
  Promise.resolve(1)
    .then(() => start.resolve('start'))
    .then(() => subtaskDefs[0].resolve('subtask_1'))
    .then(() => nestedTask1Defs[0].resolve('nested_task_1_1'))
    .then(() => nestedTask2Defs[0].resolve('nested_task_2_1'))
    .then(() => stop.resolve('stop'))
    .then(() => nestedTask1Defs[1].resolve('nested_task_1_2'))
    .then(() => nestedTask2Defs[1].resolve('nested_task_2_2'))
    .then(() => subtaskDefs[1].resolve('subtask_2'))

  function* nestedTask1() {
    try {
      actual.push(yield nestedTask1Defs[0].promise)
      actual.push(yield nestedTask1Defs[1].promise)
    } finally {
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('saga cancellation: automatic race competitor cancellation', () => {
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let winnerSubtaskDefs = arrayOfDeferred(2),
    loserSubtaskDefs = arrayOfDeferred(2),
    parallelSubtaskDefs = arrayOfDeferred(2)
  Promise.resolve(1)
    .then(() => winnerSubtaskDefs[0].resolve('winner_1'))
    .then(() => loserSubtaskDefs[0].resolve('loser_1'))
    .then(() => parallelSubtaskDefs[0].resolve('parallel_1'))
    .then(() => winnerSubtaskDefs[1].resolve('winner_2'))
    .then(() => loserSubtaskDefs[1].resolve('loser_2'))
    .then(() => parallelSubtaskDefs[1].resolve('parallel_2'))

  function* winnerSubtask() {
    try {
      actual.push(yield winnerSubtaskDefs[0].promise)
      actual.push(yield winnerSubtaskDefs[1].promise)
    } finally {
      if (yield io.cancelled()) actual.push(yield 'winner subtask cancelled')
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('saga cancellation: automatic parallel effect cancellation', () => {
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let subtask1Defs = arrayOfDeferred(2),
    subtask2Defs = arrayOfDeferred(2)
  Promise.resolve(1)
    .then(() => subtask1Defs[0].resolve('subtask_1'))
    .then(() => subtask2Defs[0].resolve('subtask_2'))
    .then(() => subtask1Defs[1].reject('subtask_1 rejection'))
    .then(() => subtask2Defs[1].resolve('subtask_2_2'))

  function* subtask1() {
    actual.push(yield subtask1Defs[0].promise)
    actual.push(yield subtask1Defs[1].promise)
  }

  function* subtask2() {
    try {
      actual.push(yield subtask2Defs[0].promise)
      actual.push(yield subtask2Defs[1].promise)
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('saga cancellation: forked children', () => {
  const actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let cancelDef = deferred()
  const rootDef = deferred()
  const childAdef = deferred()
  const childBdef = deferred()
  const neverDef = deferred()
  const defs = arrayOfDeferred(4)
  Promise.resolve()
    .then(() => childAdef.resolve('childA resolve'))
    .then(() => rootDef.resolve('root resolve'))
    .then(() => defs[0].resolve('leaf 0 resolve'))
    .then(() => childBdef.resolve('childB resolve')) //
    .then(() => cancelDef.resolve('cancel'))
    .then(() => defs[3].resolve('leaf 3 resolve'))
    .then(() => defs[2].resolve('leaf 2 resolve'))
    .then(() => defs[1].resolve('leaf 1 resolve'))

  function* main() {
    try {
      yield io.fork(childA)
      actual.push(yield rootDef.promise)
      yield io.fork(childB)
      yield neverDef.promise
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('saga cancellation: automatic race competitor cancellation', () => {
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let winnerSubtaskDefs = arrayOfDeferred(2),
    loserSubtaskDefs = arrayOfDeferred(2),
    parallelSubtaskDefs = arrayOfDeferred(2)
  Promise.resolve(1)
    .then(() => winnerSubtaskDefs[0].resolve('winner_1'))
    .then(() => loserSubtaskDefs[0].resolve('loser_1'))
    .then(() => parallelSubtaskDefs[0].resolve('parallel_1'))
    .then(() => winnerSubtaskDefs[1].resolve('winner_2'))
    .then(() => loserSubtaskDefs[1].resolve('loser_2'))
    .then(() => parallelSubtaskDefs[1].resolve('parallel_2'))

  function* winnerSubtask() {
    try {
      actual.push(yield winnerSubtaskDefs[0].promise)
      actual.push(yield winnerSubtaskDefs[1].promise)
    } finally {
      if (yield io.cancelled()) actual.push(yield 'winner subtask cancelled')
    }
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('cancel should be able to cancel multiple tasks', () => {
  const defs = arrayOfDeferred(3)
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))

  function* worker(i) {
    try {
      yield defs[i].promise
    } finally {
      if (yield io.cancelled()) {
        actual.push(i)
      }
    }
  }

  function* genFn() {
    const t1 = yield io.fork(worker, 0)
github redux-saga / redux-saga / packages / core / __tests__ / interpreter / cancellation.js View on Github external
test('saga cancellation: nested task cancellation', () => {
  let actual = []
  const middleware = sagaMiddleware()
  createStore(() => ({}), {}, applyMiddleware(middleware))
  let start = deferred(),
    stop = deferred(),
    subtaskDefs = arrayOfDeferred(2),
    nestedTask1Defs = arrayOfDeferred(2),
    nestedTask2Defs = arrayOfDeferred(2)
  Promise.resolve(1)
    .then(() => start.resolve('start'))
    .then(() => subtaskDefs[0].resolve('subtask_1'))
    .then(() => nestedTask1Defs[0].resolve('nested_task_1_1'))
    .then(() => nestedTask2Defs[0].resolve('nested_task_2_1'))
    .then(() => stop.resolve('stop'))
    .then(() => nestedTask1Defs[1].resolve('nested_task_1_2'))
    .then(() => nestedTask2Defs[1].resolve('nested_task_2_2'))
    .then(() => subtaskDefs[1].resolve('subtask_2'))

  function* nestedTask1() {
    try {
      actual.push(yield nestedTask1Defs[0].promise)
      actual.push(yield nestedTask1Defs[1].promise)
    } finally {
      if (yield io.cancelled()) actual.push(yield 'nested task 1 cancelled')

@redux-saga/deferred

Helper for creating "exposed" promise object (with resolve & reject methods).

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis

Popular @redux-saga/deferred functions