Last active
August 17, 2020 17:44
-
-
Save slorber/7ae19043ffb43d60ff17 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* runTimer(getState) { | |
while(yield take('START')) { | |
while(true) { | |
const {stop, tick} = yield race({ | |
stop : take('STOP'), | |
tick : call(wait, ONE_SECOND); | |
}) | |
if ( !stop ) { | |
yield put(actions.tick()); | |
} else { | |
break; | |
} | |
} | |
} | |
} |
@d4ncer thanks fixed
👍
I like this approach just that this if
waist my brain. I don't like else
if ( stop ) {
break;
}
yield put(actions.tick());
I like @mrsoto's suggestion. A little one-liner is more readable:
if (stop) { break }
yield put(actions.tick())
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You want to check for
rather than
because
returns undefined, causing you to break out of your loop on the first iteration.