WebStreams / WebStreams.Server

Serve APIs returning & consuming observable streams over WebSockets using .NET
Apache License 2.0
80 stars 6 forks source link

Documentation: Controller and IObservable lifecycle #1

Closed chriseldredge closed 10 years ago

chriseldredge commented 10 years ago

When reading the summary I had two questions:

How many instances of my Controller class get instantiated? One? One per web socket?

When, if ever, do the IObservable instances my action returns get disposed?

ReubenBond commented 10 years ago

Very good questions, we certainly need more documentation on this.

Exactly one instance of your controller class will be instantiated - see StreamControllerManager.GetStreamController(Type).

Subscriptions to your returned observables are disposed when: a) The socket closes. b) The socket errors. c) Your observable completes either by error or normally.

Likewise for subscriptions to observables passed into your controller method (eg, incoming stream of chat messages or commands).

Does that behaviour sound suitable to you?

Thanks for the question. By the way, we are very open to PRs :)

ReubenBond commented 10 years ago

I've written a Wiki page on Object Lifecycle - please let me know what you think.

chriseldredge commented 10 years ago

Looks pretty good. I made some minor tweaks to formatting.

Followup question: if my app creates a single IObervable for broadcasting events at the application level, do I need to do anything specific to wrap it when returning it from an action method so when the first websocket is closed it does not dispose the single instance for everyone?

ReubenBond commented 10 years ago

No, in that case you're just returning a "hot" observable. Only the individual subscriptions will be disposed. On Aug 14, 2014 12:51 AM, "Chris Eldredge" notifications@github.com wrote:

Looks pretty good. I made some minor tweaks to formatting.

Followup question: if my app creates a single IObervable for broadcasting events at the application level, do I need to do anything specific to wrap it when returning it from an action method so when the first websocket is closed it does not dispose the single instance for everyone?

— Reply to this email directly or view it on GitHub https://github.com/daprlabs/WebStreams.Server/issues/1#issuecomment-52058970 .

ReubenBond commented 10 years ago

fixed