Closed Nuhvi closed 2 years ago
Ah the query IS a stream. Use like you would any nodejs stream or async iterator
The wording could be better, (feel free to improve :)) but the "looks like this" part describes the data returned.
I couldn't get any chunks with on('data')
, however this works:
await stream.finished();
stream.closestNodes
Which are the public functions on Query, so I will leave it at that until I find a use for any other API.
It emits data, end, close. If you data was emitted the stream was prob empty.
Well, how to send data?
All I have is another nod e that is announcing:
const node = new DHT({ keyPair });
node.announce(topic);
``
So if that doesn't result in data, I am not sure what does?
See the tests, it returns the data of nodes that are already announced.
For example this one, https://github.com/hyperswarm/dht/blob/master/test/announces.js#L36-L39
I didn't wait for the announced stream to finish.
This work fine:
await node.announce(topic, keyPair).finished();
Calling
node.lookup
doesn't return the object described here: https://github.com/hyperswarm/dht#const-stream--nodelookuptopic-optionsIt returns a
Query
instance from thedht-rpc
and I can't find the described interface there either.