mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 15:02:42 +01:00
reorg again, absolute (module) imports
This commit is contained in:
31
app/util/PromiseQueue.ts
Normal file
31
app/util/PromiseQueue.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
type QueuedPromise = () => Promise<any>
|
||||
|
||||
class PromiseQueue {
|
||||
maxSimultaneously: number
|
||||
|
||||
private active = 0
|
||||
private queue: QueuedPromise[] = []
|
||||
|
||||
constructor(maxSimultaneously = 1) {
|
||||
this.maxSimultaneously = maxSimultaneously
|
||||
}
|
||||
|
||||
async enqueue<T>(func: () => Promise<T>) {
|
||||
if (++this.active > this.maxSimultaneously) {
|
||||
await new Promise(resolve => this.queue.push(resolve as QueuedPromise))
|
||||
}
|
||||
|
||||
try {
|
||||
return await func()
|
||||
} catch (err) {
|
||||
throw err
|
||||
} finally {
|
||||
this.active--
|
||||
if (this.queue.length) {
|
||||
this.queue.shift()?.()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default PromiseQueue
|
||||
13
app/util/formatDuration.ts
Normal file
13
app/util/formatDuration.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
function formatDuration(seconds: number): string {
|
||||
const s = Math.floor(seconds) % 60
|
||||
const m = Math.floor(seconds / 60) % 60
|
||||
const h = Math.floor(seconds / 60 / 60)
|
||||
|
||||
let time = `${m.toString().padStart(1, '0')}:${s.toString().padStart(2, '0')}`
|
||||
if (h > 0) {
|
||||
time = `${h}:${time}`
|
||||
}
|
||||
return time
|
||||
}
|
||||
|
||||
export default formatDuration
|
||||
7
app/util/paths.ts
Normal file
7
app/util/paths.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import RNFS from 'react-native-fs'
|
||||
|
||||
export default {
|
||||
imageCache: `${RNFS.DocumentDirectoryPath}/image_cache`,
|
||||
songCache: `${RNFS.DocumentDirectoryPath}/song_cache`,
|
||||
songs: `${RNFS.DocumentDirectoryPath}/songs`,
|
||||
}
|
||||
Reference in New Issue
Block a user