Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@d4ncer d4ncer commented Jan 16, 2016

You want to check for

if (!stop) { ... }

rather than

if (tick) { ... }

because

call(wait, ONE_SECOND)

returns undefined, causing you to break out of your loop on the first iteration.

@slorber

This comment has been minimized.

Copy link
Owner Author

@slorber slorber commented Jan 16, 2016

@d4ncer thanks fixed

@d4ncer

This comment has been minimized.

Copy link

@d4ncer d4ncer commented Jan 16, 2016

👍

@mrsoto

This comment has been minimized.

Copy link

@mrsoto mrsoto commented Sep 10, 2016

I like this approach just that this if waist my brain. I don't like else

if ( stop ) {
break;
}
yield put(actions.tick());

@granmoe

This comment has been minimized.

Copy link

@granmoe granmoe commented Sep 11, 2016

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