File tree Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,11 @@ export const useThumbnailAndWaveform = ({
31
31
32
32
const execute = useCallback ( ( ) => {
33
33
const abortController = new AbortController ( ) ;
34
+
35
+ const hasEnoughData = ( ) => {
36
+ onDone ( ) ;
37
+ } ;
38
+
34
39
parseMedia ( {
35
40
signal : abortController . signal ,
36
41
reader : src . type === 'file' ? webFileReader : fetchReader ,
@@ -114,7 +119,7 @@ export const useThumbnailAndWaveform = ({
114
119
if ( frames >= framesToGet ) {
115
120
abortController . abort ( ) ;
116
121
frame . close ( ) ;
117
- onDone ( ) ;
122
+ hasEnoughData ( ) ;
118
123
return ;
119
124
}
120
125
Original file line number Diff line number Diff line change @@ -187,6 +187,8 @@ const internalParseMedia: InternalParseMedia = async function <
187
187
}
188
188
}
189
189
190
+ await state . eventLoop . eventLoopBreakIfNeeded ( ) ;
191
+
190
192
const hasBigBuffer = iterator . bytesRemaining ( ) > 100_000 ;
191
193
192
194
if ( iterationWithThisOffset > 0 || ! hasBigBuffer ) {
Original file line number Diff line number Diff line change
1
+ import type { LogLevel } from '../log' ;
2
+ import { Log } from '../log' ;
3
+
4
+ export const eventLoopState = ( logLevel : LogLevel ) => {
5
+ let lastEventLoopBreak = Date . now ( ) ;
6
+
7
+ const eventLoopBreakIfNeeded = async ( ) => {
8
+ if ( Date . now ( ) - lastEventLoopBreak > 2_000 ) {
9
+ await new Promise < void > ( ( resolve ) => {
10
+ setTimeout ( ( ) => resolve ( ) , 50 ) ;
11
+ } ) ;
12
+ Log . verbose ( logLevel , '10ms event loop break' ) ;
13
+ lastEventLoopBreak = Date . now ( ) ;
14
+ }
15
+ } ;
16
+
17
+ return { eventLoopBreakIfNeeded} ;
18
+ } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import {flacState} from './flac-state';
9
9
import { imagesState } from './images' ;
10
10
import { isoBaseMediaState } from './iso-base-media/iso-state' ;
11
11
import { keyframesState } from './keyframes' ;
12
+ import { eventLoopState } from './last-eventloop-break' ;
12
13
import { makeMp3State } from './mp3' ;
13
14
import { riffSpecificState } from './riff' ;
14
15
import { sampleCallback } from './sample-callbacks' ;
@@ -101,6 +102,7 @@ export const makeParserState = ({
101
102
videoSection : videoSectionState ( ) ,
102
103
logLevel,
103
104
iterator,
105
+ eventLoop : eventLoopState ( logLevel ) ,
104
106
} ;
105
107
} ;
106
108
You can’t perform that action at this time.
0 commit comments