Skip to content

Commit 94dccae

Browse files
committed
添加换源超时定时器
1 parent 74ef112 commit 94dccae

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/renderer/core/music/utils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ export const getOtherSource = async(musicInfo: LX.Music.MusicInfo | LX.Download.
4949
}
5050
if (getOtherSourcePromises.has(key)) return getOtherSourcePromises.get(key)
5151

52-
const promise = musicSdk.findMusic(searchMusicInfo).then((otherSource) => {
53-
const sources: LX.Music.MusicInfoOnline[] = otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[]
54-
if (sources.length) void saveOtherSourceFromStore(musicInfo.id, sources)
55-
return sources
52+
const promise = new Promise<LX.Music.MusicInfoOnline[]>((resolve, reject) => {
53+
let timeout: null | NodeJS.Timeout = setTimeout(() => {
54+
timeout = null
55+
reject(new Error('find music timeout'))
56+
}, 20_000)
57+
musicSdk.findMusic(searchMusicInfo).then((otherSource) => {
58+
resolve(otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[])
59+
}).catch(reject).finally(() => {
60+
if (timeout) clearTimeout(timeout)
61+
})
62+
}).then((otherSource) => {
63+
if (otherSource.length) void saveOtherSourceFromStore(musicInfo.id, otherSource)
64+
return otherSource
5665
}).finally(() => {
5766
if (getOtherSourcePromises.has(key)) getOtherSourcePromises.delete(key)
5867
})

0 commit comments

Comments
 (0)