Waiting in a redux-saga
You could achieve that with a promise and a generator function:
function sleep(sec) {
return new Promise(resolve => setTimeout(resolve, sec*1000));
}
function* save({ payload }) {
yield put(pending());
yield sleep(2); //wait 2 seconds
yield put(complete());
}
Redux-sagas has a special effect for this:
delay(ms, [val])
Returns a Promise that will resolve after ms milliseconds with val.
Example:
import { delay, call } from 'redux-saga/effects'
function* someSaga(input) {
yield put(someAction())
yield delay(500)
yield put(anotherAction())
}