Skip to content
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

close channel #57

Open
minaevmike opened this issue Jul 22, 2016 · 3 comments
Open

close channel #57

minaevmike opened this issue Jul 22, 2016 · 3 comments

Comments

@minaevmike
Copy link
Contributor

Hi,
could you tell is it a bug or not. In your test

defer ch.Call(ctx, "close")
you add defer to close
https://github.com/cocaine/cocaine-framework-go/blob/master/cocaine12/locator.go#L65 there is no defer, is ok, or defer in nessesary?

@noxiouz
Copy link
Member

noxiouz commented Jul 22, 2016

Not a bug. It depends on the protocol transition.

@minaevmike
Copy link
Contributor Author

Hm, ok, is there any rule to choose call defer ch.Call(ctx, "close") or not?
Am i right that if i go to service(like elliptics) i don't need to call it, and if i go to application i need?

@noxiouz
Copy link
Member

noxiouz commented Jul 22, 2016

@minaevmike let me explain on examples.
A point is, that the trasition graph can be three types: recursive one (None), a step to another level and a dead way ({}). The idea is to lead a branch of a dispatch tree to a dead way ({}).
For example, locator's graph:

{
 0: ['resolve', {}, {0: ['value', {}], 1: ['error', {}]}], 
 1: ['connect', {}, {0: ['write', None], 1: ['error', {}], 2: ['close', {}]}], 
 2: ['refresh', {}, {0: ['value', {}], 1: ['error', {}]}], 
 3: ['cluster', {}, {0: ['value', {}], 1: ['error', {}]}], 
 4: ['publish', {0: ['discard', {}]}, {0: ['value', {}], 1: ['error', {}]}],
 5: ['routing', {0: ['discard', {}]}, {0: ['write', None], 1: ['error', {}], 2: ['close', {}]}]
}

if you call resolve, client will step to {} point, so you should close anything.
if you call publish to close you stream you have to call discard.

Application's graph:

{
 0: ['enqueue', {0: ['write', None], 1: ['error', {}], 2: ['close', {}]}, {0: ['write', None], 1: ['error', {}], 2: ['close', {}]}], 
 1: ['info', {}, {0: ['value', {}], 1: ['error', {}]}], 2: ['control', {0: ['write', None], 1: ['error', {}], 2: ['close' {}]
}

if you call enqueue, you move to the point where write, error, close are available. It's client's stream. Calling write returns you to the same point (None). It means you can write as many chunks as you want. To close the stream you must call either close or error.

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

No branches or pull requests

2 participants