Skip to content

Instantly share code, notes, and snippets.

@radzionc
Created January 14, 2018 10:08
Show Gist options
  • Select an option

  • Save radzionc/b60c3632d8543fdf7e85119b2baf22b8 to your computer and use it in GitHub Desktop.

Select an option

Save radzionc/b60c3632d8543fdf7e85119b2baf22b8 to your computer and use it in GitHub Desktop.
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