Skip to content
This repository has been archived by the owner on Nov 12, 2019. It is now read-only.

Read only stream? #24

Open
mbrevoort opened this issue Jul 9, 2013 · 9 comments
Open

Read only stream? #24

mbrevoort opened this issue Jul 9, 2013 · 9 comments

Comments

@mbrevoort
Copy link
Collaborator

Is there as way to create a read-only stream between two documents? So if you have document A and B, A stream updates to B but B doesn't send updates to A. Instead B is thought to be read-only.

I've tried to not pipe the B stream back to A but this resulted in B not getting all of the existing state from A:

A.createStream()
  .pipe(B.createStream());

Is there a way to do this currently?

@juliangruber
Copy link

you could write a scuttlebutt subclass that only accepts changes from the scuttlebutt that has been piped to it, then you can do:

A.createStream().pipe(oneWay()).pipe(B.createStream());

@Raynos
Copy link
Contributor

Raynos commented Jul 9, 2013

x.createStream({ writable: false })

@mbrevoort
Copy link
Collaborator Author

@Raynos oh man, that just made my day :)

@juliangruber
Copy link

every scuttlebutt would get that, right? then I think that's the better solution. oh, is that already in scuttlebutt?

@Raynos
Copy link
Contributor

Raynos commented Jul 9, 2013

every scuttlebutt has createStream({ writable: Boolean, readable: Boolean })

@Raynos
Copy link
Contributor

Raynos commented Jul 9, 2013

Both default to true

@dominictarr
Copy link
Owner

oh, hmm. that feature was intended for persistance - using it that way will work,
but will just resend old data, instead of only sending new data.
You really want to still send the vector clock hand shake,

okay, I just added a sendClock option.

now, you can create a scuttlebutt stream that will emit updates, but not send them,
like this:

var s1 = master.createStream({writable: false, sendClock: true})
var s2 = slave.createStream({readable: false, sendClock: true})

just added this in scuttlebutt 5.6, update any subclass and you should get that.

@mbrevoort
Copy link
Collaborator Author

@dominictarr that's excellent, thanks!

What does setting the slave stream to readable: false do? Does it prevent that stream from propagating changes down stream? So if you just set the master as writable: false and didn't set the slave as readable: false, the slave stream would still send changes over the wire to the master but the master would just ignore them? Is that the intention?

@dominictarr
Copy link
Owner

readable: false tells it not to emit any updates after the vector clock.
So you probably don't need that, but it will stop it spamming if you are also setting properties on it locally.

note that this is a setting on the stream - you can have a pair that is master(a) -> slave(b), but have still have master(a) <-> master(c) or even master(a) -> slave(b); master(c) -> slave(b). setting readable: false on b's streams prevent it from sending update received from another master(c) back to master(a), etc.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants