-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protocol stream .end()
not working as expected
#366
Comments
When you do const s = core.replicate(true)
s.on('end', () => s.end())
// ...
s.end() I think this is automatically handled so you should only need to do Except if you listen to the event like |
Thanks @LuKks that makes sense, however this is not the behaviour I am seeing: |
Ok did some digging and got the following results. It seems like import Hypercore from 'hypercore'
import RAM from 'random-access-memory'
const core1 = new Hypercore(RAM)
await core1.ready()
const core2 = new Hypercore(RAM, core1.key)
const s1 = core1.replicate(true)
const s2 = core2.replicate(false)
s1.on('end', () => console.log('s1 end'))
s1.on('close', () => console.log('s1 close'))
s2.on('end', () => console.log('s2 end'))
s2.on('close', () => console.log('s2 close'))
s1.pipe(s2).pipe(s1)
s2.end() This code logs nothing, either when calling If I await process.nextTick I get different results depending on which core I await and which stream I end: await new Promise(res => process.nextTick(res))
s1.end()
// s1 end
// s1 close
// s2 close await new Promise(res => process.nextTick(res))
s2.end()
// s2 end
// s1 end
// s1 close If I await setTimeout(0) then I get consistent, but not quite what I would expect based on your comment. await new Promise(res => setTimeout(res, 0))
s1.end()
// s1 end
// s1 close
// s2 close await new Promise(res => setTimeout(res, 0))
s2.end()
// s2 end
// s2 close
// s1 close |
Try commenting out the lines where you listen to |
Done: nothing logged (e.g. no 'close' events logging) |
Possibly related? mafintosh/streamx#72 |
I was about to say that it sounds like a bug on |
Meanwhile, instead of commenting it out do this:
And try again without waiting any tick |
Unsure if you can end these streams atm. We tend to use the replicate(stream) api everywhere with a swarm stream, and the stream returned works a bit differently, but we'll look into it. |
The end event on the protocol stream returned by
core.replicate()
does not seem to propogate as expected.Use case:
I want to gracefully end a replication stream without destroying it.
Expected behaviour:
I would expect the above code to output
end
. It doesn't. There is a scenario where it does work: if the core that is replicating is a read-only peer, and you calls.end()
after first callingcore.update()
. There does not seem to be a way to end the replication stream for the writer core.Minimal reproduction:
The text was updated successfully, but these errors were encountered: