slsk-client icon indicating copy to clipboard operation
slsk-client copied to clipboard

searchStream

Open mikevercoelen opened this issue 5 years ago • 3 comments

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

mikevercoelen avatar May 18 '19 10:05 mikevercoelen

Hi, I think that you can use https://github.com/f-hj/slsk-client#events to get results while you're receiving it

f-hj avatar May 23 '19 12:05 f-hj

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

mikevercoelen avatar May 24 '19 09:05 mikevercoelen

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
});

carcabot avatar Jun 14 '19 13:06 carcabot