Skip to content

Instantly share code, notes, and snippets.

@alant
Created December 24, 2018 11:03
Show Gist options
  • Save alant/23c9005390b3141d8053c7c225fc74f5 to your computer and use it in GitHub Desktop.
Save alant/23c9005390b3141d8053c7c225fc74f5 to your computer and use it in GitHub Desktop.
...
function* pollSagaWorker(dataKey) {
while (true) {
const contracts = yield select(getContracts);
if (contracts.SimpleStorage.synced) {
const storedValueObj = contracts.SimpleStorage.storedData_[dataKey];
if (storedValueObj && storedValueObj.value) {
yield put({ type: 'GOT_STORED_VALUE', storedValue: storedValueObj.value });
}
}
yield call(delay, 200);
}
}
function* getStoredValueWatcher() {
while (true) {
yield take('GET_STORED_VALUE');
yield put({ type: 'GETTING_STORED_VALUE' });
const drizzle = yield select(getDrizzle);
const dataKey = drizzle.contracts.SimpleStorage.methods.storedData_.cacheCall();
yield race([
call(pollSagaWorker, dataKey),
take('GOT_STORED_VALUE')
])
}
}
export default function* root() {
...
yield getStoredValueWatcher();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment