Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { call, put, delay, all } = require('redux-saga/effects');
- const { runSaga, stdChannel } = require("redux-saga");
- // Setup
- const channel = stdChannel/*<never>*/();
- const myIO/*: RunSagaOptions<never, never>*/ = {
- // this will be used to orchestrate take and put Effects
- channel,
- // this will be used to resolve put Effects
- dispatch(output) {
- throw new Error('[PUT] This saga is not setup with a store connection: ' + output);
- },
- // this will be used to resolve select Effects
- getState() {
- throw new Error('[SELECT] This saga is not setup with a store connection');
- },
- };
- // Main code
- function callApi(url) {
- console.log(new Date() + 'Calling ' + url);
- return Promise.resolve(['Yass']);
- }
- function* callApiWithDelay(url) {
- const result = yield call(callApi, url);
- yield delay(5000);
- return result;
- }
- function* fetchResults() {
- console.log(new Date() + 'fetchResults starting');
- const listing = yield callApiWithDelay('/list')
- for(const item of listing) {
- yield callApiWithDelay('/res/'+item)
- }
- console.log(new Date() + 'fetchResults finished');
- }
- function* mainLoop() {
- yield delay(100); // Startup delay so console logs make sense
- while(true) {
- yield all([
- call(fetchResults),
- //delay(1000 * 60 * 20),
- delay(1000 * 7),
- ]);
- }
- }
- const task = runSaga( myIO, mainLoop )
Advertisement
Add Comment
Please, Sign In to add comment