multi hashtags support
This commit is contained in:
parent
dacc31ce77
commit
4ff59af24c
|
@ -27,7 +27,7 @@
|
|||
import Controls from '/components/Controls.svelte'
|
||||
import Queue from '/components/Queue.svelte'
|
||||
import Viewer from '/components/Viewer.svelte'
|
||||
import { hashtagIterator } from '/services/mastodon.js'
|
||||
import { hashtagIterator, combinedIterator } from '/services/mastodon.js'
|
||||
import { mkTracksIterator } from '/services/misc.js'
|
||||
|
||||
import { domain, hashtags, queue, next, current, enqueueing, select } from '/store.js'
|
||||
|
@ -36,7 +36,13 @@
|
|||
let currentUnsubcribe = null
|
||||
|
||||
onMount(async () => {
|
||||
const iterator = mkTracksIterator(hashtagIterator(get(domain), get(hashtags)[0]))
|
||||
// const iterator = mkTracksIterator(hashtagIterator(get(domain), get(hashtags)[0]))
|
||||
const domainValue = get(domain)
|
||||
const hashtagsValue = get(hashtags)
|
||||
|
||||
const iterator = combinedIterator(
|
||||
hashtagsValue.map(hashtag => mkTracksIterator(hashtagIterator(domainValue, hashtag)))
|
||||
)
|
||||
|
||||
const { value: first } = await iterator.next()
|
||||
|
||||
|
|
|
@ -75,8 +75,28 @@ export async function* hashtagIterator(domain, hashtag) {
|
|||
|
||||
values[index] = iterators[index].next()
|
||||
|
||||
console.log(`Resolver ${domain} #${hashtag} : resolved with iterator ${index} status ${value.id}`)
|
||||
console.log(`Resolver ${domain} #${hashtag} : resolved with iterator ${index}`)
|
||||
yield value
|
||||
}
|
||||
}
|
||||
|
||||
export async function* combinedIterator(iterators) {
|
||||
const values = iterators.map(iterator => iterator.next())
|
||||
|
||||
while (true) {
|
||||
const promises = values.map((promise, index) => promise.then(result => ({ index, result })))
|
||||
const promisesValues = await Promise.all(promises)
|
||||
|
||||
const sorted = promisesValues
|
||||
.sort((a, b) =>{
|
||||
new Date(a.result.value.status.created_at) - new Date(b.result.value.status.created_at)
|
||||
})
|
||||
|
||||
const { index, result: { done, value } } = sorted[0]
|
||||
|
||||
values[index] = iterators[index].next()
|
||||
|
||||
console.log(`CombinedResolver : resolved with iterator ${index}`)
|
||||
yield value
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue