mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-04 16:18:56 +08:00
添加换源超时定时器
This commit is contained in:
parent
6f3b61a9bd
commit
7b0a438f4c
@ -9,6 +9,7 @@ import { langS2T, toNewMusicInfo, toOldMusicInfo } from '@/utils'
|
|||||||
import { assertApiSupport } from '@/utils/tools'
|
import { assertApiSupport } from '@/utils/tools'
|
||||||
import settingState from '@/store/setting/state'
|
import settingState from '@/store/setting/state'
|
||||||
import { requestMsg } from '@/utils/message'
|
import { requestMsg } from '@/utils/message'
|
||||||
|
import BackgroundTimer from 'react-native-background-timer'
|
||||||
|
|
||||||
|
|
||||||
const getOtherSourcePromises = new Map()
|
const getOtherSourcePromises = new Map()
|
||||||
@ -48,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 = 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 | number = BackgroundTimer.setTimeout(() => {
|
||||||
if (sources.length) void saveOtherSourceFromStore(musicInfo.id, sources)
|
timeout = null
|
||||||
return sources
|
reject(new Error('find music timeout'))
|
||||||
|
}, 20_000)
|
||||||
|
findMusic(searchMusicInfo).then((otherSource) => {
|
||||||
|
resolve(otherSource.map(toNewMusicInfo) as LX.Music.MusicInfoOnline[])
|
||||||
|
}).catch(reject).finally(() => {
|
||||||
|
if (timeout) BackgroundTimer.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…
x
Reference in New Issue
Block a user