Skip to content

Commit ee746f6

Browse files
authored
fix: read stream data using lp stream (#242)
1 parent ed64183 commit ee746f6

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/libp2p-daemon-protocol/src/stream-handler.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ export class StreamHandler {
2727
/**
2828
* Read and decode message
2929
*/
30-
async read (): Promise<Uint8Array | undefined> {
31-
// @ts-expect-error decoder is really a generator
32-
const msg = await this.decoder.next()
33-
if (msg.value != null) {
34-
return msg.value.subarray()
30+
async read (): Promise<Uint8ArrayList | undefined> {
31+
try {
32+
return await this.lp.read()
33+
} catch (err) {
34+
log.error('read received no value', err)
3535
}
36-
37-
log('read received no value, closing stream')
38-
// End the stream, we didn't get data
39-
await this.close()
4036
}
4137

4238
async write (msg: Uint8Array | Uint8ArrayList): Promise<void> {

0 commit comments

Comments
 (0)