Created
January 14, 2018 10:08
-
-
Save radzionc/b60c3632d8543fdf7e85119b2baf22b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function delay(duration) { | |
| const promise = new Promise(resolve => { | |
| setTimeout(() => resolve(true), duration) | |
| }) | |
| return promise | |
| } | |
| function* getCost(successAction) { | |
| try { | |
| const { startLocation, endLocation, apiKey } = yield select() | |
| const data = yield call( | |
| getEstimation, | |
| apiKey, | |
| startLocation.latitude, | |
| startLocation.longitude, | |
| endLocation.latitude, | |
| endLocation.longitude | |
| ) | |
| yield put(requestToUberMade()) | |
| yield put(successAction(data)) | |
| } catch (error) { | |
| yield put(uberEstimationRequestFailed(error)) | |
| } | |
| } | |
| export function* lookForCostSaga() { | |
| yield* getCost(rideValidated) | |
| function* polling() { | |
| const { waitingTime, page } = yield select() | |
| if (page !== 'Chart') return | |
| const requestFrequency = | |
| Math.round(60 / (MAX_REQUEST_IN_HOUR / waitingTime)) * 1000 | |
| yield* getCost(newEstimationReceived) | |
| yield call(delay, requestFrequency) | |
| yield* polling() | |
| } | |
| yield* polling() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment