File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -21,12 +21,14 @@ module.exports = (_options = {}) => {
21
21
let Core = null ;
22
22
let ffmpeg = null ;
23
23
let runResolve = null ;
24
+ let runReject = null ;
24
25
let running = false ;
25
26
let progress = optProgress ;
26
27
const detectCompletion = ( message ) => {
27
28
if ( message === 'FFMPEG_END' && runResolve !== null ) {
28
29
runResolve ( ) ;
29
30
runResolve = null ;
31
+ runReject = null ;
30
32
running = false ;
31
33
}
32
34
} ;
@@ -126,9 +128,10 @@ module.exports = (_options = {}) => {
126
128
throw Error ( 'ffmpeg.wasm can only run one command at a time' ) ;
127
129
} else {
128
130
running = true ;
129
- return new Promise ( ( resolve ) => {
131
+ return new Promise ( ( resolve , reject ) => {
130
132
const args = [ ...defaultArgs , ..._args ] . filter ( ( s ) => s . length !== 0 ) ;
131
133
runResolve = resolve ;
134
+ runReject = reject
132
135
ffmpeg ( ...parseArgs ( Core , args ) ) ;
133
136
} ) ;
134
137
}
@@ -177,6 +180,10 @@ module.exports = (_options = {}) => {
177
180
if ( Core === null ) {
178
181
throw NO_LOAD ;
179
182
} else {
183
+ // if there's any pending runs, reject them
184
+ if ( runReject ) {
185
+ runReject ( 'ffmpeg has exited' )
186
+ }
180
187
running = false ;
181
188
Core . exit ( 1 ) ;
182
189
Core = null ;
Original file line number Diff line number Diff line change @@ -48,6 +48,16 @@ describe('run()', () => {
48
48
}
49
49
} , 500 ) ;
50
50
} ) . timeout ( TIMEOUT ) ;
51
+
52
+ it ( 'should terminate the run if exit is called' , async ( ) => {
53
+ const ffmpeg = createFFmpeg ( OPTIONS ) ;
54
+ await ffmpeg . load ( ) ;
55
+
56
+ ffmpeg . run ( '-h' ) . catch ( e => {
57
+ expect ( e ) . to . be . equal ( 'ffmpeg has exited' )
58
+ } ) ;
59
+ expect ( ffmpeg . exit ( ) ) . to . throw ( ) ;
60
+ } ) . timeout ( TIMEOUT ) ;
51
61
} ) ;
52
62
53
63
describe ( 'FS()' , ( ) => {
You can’t perform that action at this time.
0 commit comments