@@ -7,6 +7,7 @@ import window, { alert, document, location } from "libs/window";
7
7
import _ from "lodash" ;
8
8
import memoizeOne from "memoize-one" ;
9
9
import messages from "messages" ;
10
+ import { buffers } from "redux-saga" ;
10
11
import { actionChannel , call , delay , fork , put , race , take } from "typed-redux-saga" ;
11
12
import { ControlModeEnum } from "viewer/constants" ;
12
13
import { getMagInfo } from "viewer/model/accessors/dataset_accessor" ;
@@ -53,6 +54,7 @@ import type {
53
54
SkeletonTracing ,
54
55
VolumeTracing ,
55
56
} from "viewer/store" ;
57
+ import type { Action } from "../actions/actions" ;
56
58
import { takeEveryWithBatchActionSupport } from "./saga_helpers" ;
57
59
58
60
const ONE_YEAR_MS = 365 * 24 * 3600 * 1000 ;
@@ -388,6 +390,7 @@ export function* setupSavingForTracingType(
388
390
let prevTdCamera = yield * select ( ( state ) => state . viewModeData . plane . tdCamera ) ;
389
391
yield * call ( ensureWkReady ) ;
390
392
393
+ const actionBuffer = buffers . expanding < Action > ( ) ;
391
394
const tracingActionChannel = yield * actionChannel (
392
395
tracingType === "skeleton"
393
396
? [
@@ -399,20 +402,30 @@ export function* setupSavingForTracingType(
399
402
"SET_TRACING" ,
400
403
]
401
404
: [ ...VolumeTracingSaveRelevantActions , ...FlycamActions , ...ViewModeSaveRelevantActions ] ,
405
+ actionBuffer ,
402
406
) ;
407
+
408
+ // See Model.ensureSavedState for an explanation of this action channel.
403
409
const ensureDiffedChannel = yield * actionChannel < EnsureTracingsWereDiffedToSaveQueueAction > (
404
410
"ENSURE_TRACINGS_WERE_DIFFED_TO_SAVE_QUEUE" ,
405
411
) ;
406
412
407
413
while ( true ) {
408
- // todop: prioritize tracingAction?
409
- const { ensureAction } = yield * race ( {
410
- _tracingAction : take ( tracingActionChannel ) ,
411
- ensureAction : take ( ensureDiffedChannel ) ,
412
- } ) ;
413
- if ( ensureAction != null ) {
414
- ensureAction . callback ( tracingId ) ;
415
- continue ;
414
+ // Prioritize consumption of tracingActionChannel since we don't want to
415
+ // reply to the ENSURE_TRACINGS_WERE_DIFFED_TO_SAVE_QUEUE action if there
416
+ // are unprocessed user actions.
417
+ if ( ! actionBuffer . isEmpty ( ) ) {
418
+ yield * take ( tracingActionChannel ) ;
419
+ } else {
420
+ // Wait for either a user action or the "ensureAction".
421
+ const { ensureAction } = yield * race ( {
422
+ _tracingAction : take ( tracingActionChannel ) ,
423
+ ensureAction : take ( ensureDiffedChannel ) ,
424
+ } ) ;
425
+ if ( ensureAction != null ) {
426
+ ensureAction . callback ( tracingId ) ;
427
+ continue ;
428
+ }
416
429
}
417
430
418
431
// The allowUpdate setting could have changed in the meantime
0 commit comments