How to use the redux-saga/effects.delay function in redux-saga

To help you get started, we’ve selected a few redux-saga 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 reimagined / resolve / examples / hacker-news / client / sagas / story-create-saga.js View on Github external
function*(action) {
      while (true) {
        try {
          const { result } = yield api.loadReadModelState({
            readModelName: 'HackerNews',
            resolverName: 'story',
            resolverArgs: { id: action.aggregateId }
          })

          if (JSON.parse(result) == null) {
            yield delay(300)
            continue
          }

          yield put(routerActions.push(`/storyDetails/${action.aggregateId}`))
          break
        } catch (error) {
          // eslint-disable-next-line no-console
          console.warn(error)
          break
        }
      }
    }
  )
github podlove / podlove-ui / packages / player / sagas / transcripts.js View on Github external
export function* init({ selectSpeakers, selectChapters, selectPlaytime }, { payload }) {
  // Bump one cycle so chapters and speakers are available
  yield delay(0)
  const speakers = yield select(selectSpeakers)
  const chapters = yield select(selectChapters)

  const assignSpeakers = mapSpeakers(speakers)
  const transcripts = compose(
    sortBy(prop('start')),
    concat(transformChapters(chapters)),
    assignSpeakers,
    transformTranscript,
    getTranscripts
  )(payload)

  // don't run transcripts logic if no transcripts are available
  if (transcripts.length <= chapters.length) {
    return
  }
github decentraland / builder / src / modules / editor / sagas.ts View on Github external
// wait for editor to be ready
    let ready: boolean = yield select(isReady)
    while (!ready) {
      const readyAction: SetEditorReadyAction = yield take(SET_EDITOR_READY)
      ready = readyAction.payload.isReady
    }

    // wait for assets to load
    let loading: boolean = yield select(isLoading)
    while (loading) {
      const loadingAction: SetEditorLoadingAction = yield take(SET_EDITOR_LOADING)
      loading = loadingAction.payload.isLoading
    }

    // rendering leeway
    yield delay(2000)

    const screenshot = yield call(() => editorWindow.editor.takeScreenshot())
    if (!screenshot) return

    const thumbnail = yield call(() => resizeScreenshot(screenshot, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT))
    if (!thumbnail) return

    yield put(editProjectThumbnail(currentProject.id, thumbnail))
  } catch (e) {
    // skip screenshot
  }
  yield put(setScreenshotReady(true))
}
github fusor / mig-ui / src / app / common / duck / sagas.ts View on Github external
export function* successTimeoutSaga(action) {
  try {
    yield put(AlertActions.alertSuccess(action.params));
    yield delay(5000);
    yield put(AlertActions.alertClear());
  } catch (error) {
    yield put(AlertActions.alertClear());
  }
}
github vocoWone / reaux / src / module / main / index.ts View on Github external
*onLoad(): SagaIterator {
        yield delay(2000, {});
    }
github Altinn / altinn-studio / src / studio / src / designer / frontend / app-development / sharedResources / appRelease / create / createAppReleaseSagas.ts View on Github external
function* createReleaseSaga({
  tagName,
  name,
  body,
  targetCommitish,
}: ICreateReleaseAction): SagaIterator {
  try {
    const responseData: any = yield call(post, releasesUrlPost, {
      tagName,
      name,
      body,
      targetCommitish,
    });
    yield delay(2000);
    yield call(AppReleaseActionDispatcher.createAppReleaseFulfilled, responseData);
  } catch (err) {
    if (checkIfAxiosError(err)) {
      const { response: { status } } = err as AxiosError;
      yield call(AppReleaseActionDispatcher.createAppReleaseRejected, status);
    }
  }
}
github bandprotocol / band / app / src / sagas / index.js View on Github external
yield put(updateClient(provider))
          yield put(dumpCurrent())
          window.location.reload(true)
        }
        yield put(updateClient(provider))
      } else {
        const currentUser = yield select(currentUserSelector)
        if (currentUser !== 'NOT_SIGNIN') {
          yield put(setUserAddress('NOT_SIGNIN'))
          yield put(updateClient())
          localStorage.removeItem('walletType')
          yield put(dumpCurrent())
        }
      }
    }
    yield delay(1000)
  }
}
github raindropio / mobile / src / data / modules / api.js View on Github external
function* req(url, options) {
	var finalURL = API_ENDPOINT_URL + url

	if (url.indexOf('/') == 0)
		finalURL = APP_BASE_URL + url
	else if (url.indexOf('http') == 0)
		finalURL = url

	for(let i = 0; i < API_RETRIES; i++){
		try{
			const winner = yield race({
				req: call(fetchWrap, finalURL, options),
				t: delay(API_TIMEOUT)
			})

			if (!winner.req)
				throw new Error('timeout')

			return winner.req;
		}catch({message=''}){
			if (message == 'timeout')
				break;
			else if(i < API_RETRIES-1) {
				yield delay(100); //stop 100ms and try again
			}
		}
	}

	throw new Error('failed to load '+finalURL)
github dai-shi / react-tracked / examples / 13_saga / src / store.ts View on Github external
function* userFetcher(action: AsyncActionFetch) {
  try {
    yield put({ type: 'START_FETCH_USER' });
    const response = yield call(() => fetch(`https://reqres.in/api/users/${action.id}?delay=1`));
    yield put({ type: 'CONTINUE_FETCH_USER' });
    const data = yield call(() => response.json());
    yield delay(500);
    const firstName = data.data.first_name;
    if (typeof firstName !== 'string') throw new Error();
    yield put({ type: 'FINISH_FETCH_USER', firstName });
  } catch (e) {
    yield put({ type: 'ERROR_FETCH_USER' });
  }
}