slsk-client
slsk-client copied to clipboard
searchStream
Instead of waiting for a timeout, search results could appear in a stream / event bus.
Is this something that would be possible? I would love to put in the work, but I have no idea where to start, if someone can give me pointers and advise if this is possible or not, that would be very helpful.
Thanks
Hi, I think that you can use https://github.com/f-hj/slsk-client#events to get results while you're receiving it
The ideal interface would be a stream.
How it works currently is: you search, until the timeout.
What about if you have a UI where you search infinite till the user want's it to stop?
If we use streams we could just stop it, and use on.data
to handle events. Makes more sense to me
Hi @mikevercoelen ,
There must be a timeout to prevent loading too much memory.
I think it's enough to use event function, it helps you to use results before search is finished.
// connect
// ....
client.search({
req: 'random',
timeout: 5000 // you can increase if you want a deeper search
}, (err, res) => {
if (err) return console.log(err)
})
// use event function
client.on('found', function(result) {
console.log(result)
// you will get result in real time
});