refactor: split downloader into modules
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
let isPaused = false;
|
||||
let pauseResolve = null;
|
||||
|
||||
function togglePause() {
|
||||
if (isPaused) {
|
||||
isPaused = false;
|
||||
if (pauseResolve) {
|
||||
pauseResolve();
|
||||
pauseResolve = null;
|
||||
}
|
||||
console.log('\n ▶️ 已恢复下载');
|
||||
} else {
|
||||
isPaused = true;
|
||||
console.log('\n ⏸ 已暂停 (再按 p 恢复)');
|
||||
}
|
||||
}
|
||||
|
||||
async function waitIfPaused() {
|
||||
if (!isPaused) return;
|
||||
await new Promise(resolve => { pauseResolve = resolve; });
|
||||
}
|
||||
|
||||
module.exports = { togglePause, waitIfPaused };
|
||||
Reference in New Issue
Block a user