1+ import { type Flushable , inFlushUnused , planFlush } from './asyncFlush' ;
12import { RawStoreFlags } from './store' ;
23import { checkNotInNotificationPhase , RawStoreWritable } from './storeWritable' ;
34import { activeConsumer , untrack } from './untrack' ;
45
5- let flushUnusedQueue : RawStoreTrackingUsage < any > [ ] | null = null ;
6- let inFlushUnused = false ;
7-
8- export const flushUnused = ( ) : void => {
9- // Ignoring coverage for the following lines because, unless there is a bug in tansu (which would have to be fixed!)
10- // there should be no way to trigger this error.
11- /* v8 ignore next 3 */
12- if ( inFlushUnused ) {
13- throw new Error ( 'assert failed: recursive flushUnused call' ) ;
14- }
15- inFlushUnused = true ;
16- try {
17- const queue = flushUnusedQueue ;
18- if ( queue ) {
19- flushUnusedQueue = null ;
20- for ( let i = 0 , l = queue . length ; i < l ; i ++ ) {
21- const producer = queue [ i ] ;
22- producer . flags &= ~ RawStoreFlags . FLUSH_PLANNED ;
23- producer . checkUnused ( ) ;
24- }
25- }
26- } finally {
27- inFlushUnused = false ;
28- }
29- } ;
30-
31- export abstract class RawStoreTrackingUsage < T > extends RawStoreWritable < T > {
6+ export abstract class RawStoreTrackingUsage < T > extends RawStoreWritable < T > implements Flushable {
327 private extraUsages = 0 ;
338 abstract startUse ( ) : void ;
349 abstract endUse ( ) : void ;
@@ -53,13 +28,8 @@ export abstract class RawStoreTrackingUsage<T> extends RawStoreWritable<T> {
5328 if ( inFlushUnused || flags & RawStoreFlags . HAS_VISIBLE_ONUSE ) {
5429 this . flags &= ~ RawStoreFlags . START_USE_CALLED ;
5530 untrack ( ( ) => this . endUse ( ) ) ;
56- } else if ( ! ( flags & RawStoreFlags . FLUSH_PLANNED ) ) {
57- this . flags |= RawStoreFlags . FLUSH_PLANNED ;
58- if ( ! flushUnusedQueue ) {
59- flushUnusedQueue = [ ] ;
60- queueMicrotask ( flushUnused ) ;
61- }
62- flushUnusedQueue . push ( this ) ;
31+ } else {
32+ planFlush ( this ) ;
6333 }
6434 }
6535 }
0 commit comments