Merge pull request #296 from pikax/cancel_run_if_exited
fix: Cancel run promise if the exit() is called
This commit is contained in:
commit
478d4c46c7
@ -21,12 +21,14 @@ module.exports = (_options = {}) => {
|
|||||||
let Core = null;
|
let Core = null;
|
||||||
let ffmpeg = null;
|
let ffmpeg = null;
|
||||||
let runResolve = null;
|
let runResolve = null;
|
||||||
|
let runReject = null;
|
||||||
let running = false;
|
let running = false;
|
||||||
let progress = optProgress;
|
let progress = optProgress;
|
||||||
const detectCompletion = (message) => {
|
const detectCompletion = (message) => {
|
||||||
if (message === 'FFMPEG_END' && runResolve !== null) {
|
if (message === 'FFMPEG_END' && runResolve !== null) {
|
||||||
runResolve();
|
runResolve();
|
||||||
runResolve = null;
|
runResolve = null;
|
||||||
|
runReject = null;
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -126,9 +128,10 @@ module.exports = (_options = {}) => {
|
|||||||
throw Error('ffmpeg.wasm can only run one command at a time');
|
throw Error('ffmpeg.wasm can only run one command at a time');
|
||||||
} else {
|
} else {
|
||||||
running = true;
|
running = true;
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve, reject) => {
|
||||||
const args = [...defaultArgs, ..._args].filter((s) => s.length !== 0);
|
const args = [...defaultArgs, ..._args].filter((s) => s.length !== 0);
|
||||||
runResolve = resolve;
|
runResolve = resolve;
|
||||||
|
runReject = reject
|
||||||
ffmpeg(...parseArgs(Core, args));
|
ffmpeg(...parseArgs(Core, args));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -177,6 +180,10 @@ module.exports = (_options = {}) => {
|
|||||||
if (Core === null) {
|
if (Core === null) {
|
||||||
throw NO_LOAD;
|
throw NO_LOAD;
|
||||||
} else {
|
} else {
|
||||||
|
// if there's any pending runs, reject them
|
||||||
|
if(runReject) {
|
||||||
|
runReject('ffmpeg has exited')
|
||||||
|
}
|
||||||
running = false;
|
running = false;
|
||||||
try {
|
try {
|
||||||
Core.exit(1);
|
Core.exit(1);
|
||||||
|
@ -48,6 +48,16 @@ describe('run()', () => {
|
|||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
}).timeout(TIMEOUT);
|
}).timeout(TIMEOUT);
|
||||||
|
|
||||||
|
it('should terminate the run if exit is called', async () => {
|
||||||
|
const ffmpeg = createFFmpeg(OPTIONS);
|
||||||
|
await ffmpeg.load();
|
||||||
|
|
||||||
|
ffmpeg.run('-h').catch(e=> {
|
||||||
|
expect(e).to.be.equal('ffmpeg has exited')
|
||||||
|
});
|
||||||
|
expect(ffmpeg.exit()).to.throw();
|
||||||
|
}).timeout(TIMEOUT);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('FS()', () => {
|
describe('FS()', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user