添加换源超时定时器
parent
74ef112d57
commit
94dccae48a
|
@ -49,10 +49,19 @@ export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download.
|
||||||
}
|
}
|
||||||
if (getOtherSourcePromises.has(key)) return getOtherSourcePromises.get(key)
|
if (getOtherSourcePromises.has(key)) return getOtherSourcePromises.get(key)
|
||||||
|
|
||||||
const promise = musicSdk.findMusic(searchMusicInfo).then((otherSource) => {
|
const promise = new Promise<LX.Music.MusicInfoOnline[]>((resolve, reject) => {
|
||||||
const sources: LX.Music.MusicInfoOnline[] = otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[]
|
let timeout: null | NodeJS.Timeout = setTimeout(() => {
|
||||||
if (sources.length) void saveOtherSourceFromStore(musicInfo.id, sources)
|
timeout = null
|
||||||
return sources
|
reject(new Error('find music timeout'))
|
||||||
|
}, 20_000)
|
||||||
|
musicSdk.findMusic(searchMusicInfo).then((otherSource) => {
|
||||||
|
resolve(otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[])
|
||||||
|
}).catch(reject).finally(() => {
|
||||||
|
if (timeout) clearTimeout(timeout)
|
||||||
|
})
|
||||||
|
}).then((otherSource) => {
|
||||||
|
if (otherSource.length) void saveOtherSourceFromStore(musicInfo.id, otherSource)
|
||||||
|
return otherSource
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
if (getOtherSourcePromises.has(key)) getOtherSourcePromises.delete(key)
|
if (getOtherSourcePromises.has(key)) getOtherSourcePromises.delete(key)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue