~vesto/grooveboat

4c6dae170428ca898aa769d034b60c327778ae80 — Steve Gattuso 5 years ago 5b20c65
prevent race condition while waiting for tracks

... to begin
1 files changed, 11 insertions(+), 1 deletions(-)

M src/js/services/jukebox.js
M src/js/services/jukebox.js => src/js/services/jukebox.js +11 -1
@@ 249,7 249,17 @@ function* playTrack({startedAt, track}) {
  // we end early let's delay for a bit so we don't need to seek
  const now = (+new Date()) / 1000;
  if (now - startedAt < 0) {
    yield delay((startedAt - now) * 1000);
    // Prevent race conditions, ie if the track gets stopped while we're
    // delaying for the begin time
    const {canceled, stopped} = yield race({
      finished: delay((startedAt - now) * 1000),
      canceled: take(ActionTypes.PLAY_TRACK),
      stopped: take(ActionTypes.STOP_TRACK),
    });

    if (canceled || stopped) {
      return;
    }
  }

  yield put(Actions.playTrackSuccess({