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

Não utilizar os.Exit pois dessa forma deferred funcs não executam #5

Closed
txgruppi opened this issue Apr 28, 2015 · 7 comments
Closed
Assignees
Milestone

Comments

@txgruppi
Copy link

Quando usando os.Exit o processo termina imediatamente, impedindo que deferred funcs sejam executadas.

O ideal é retornar o erro e fazer que esse erro chegue até 'quem' for responsável por tratar isso. return permite a execução de deferred funcs.

@andreyvital andreyvital self-assigned this Apr 28, 2015
@andreyvital andreyvital added this to the 0.0.1 milestone Apr 28, 2015
@andreyvital
Copy link
Contributor

Sugestões? se eu tiver que tratar o erro no "owner"...I mean, no principal, util.Invariant perde o sentido, a ideia é quebrar se a condicional falhar!

Veja isso: https://groups.google.com/forum/#!topic/golang-nuts/UYoaWk6oJbY e isso: https://gist.github.com/philpennock/3948444

Algo interessante?

@txgruppi
Copy link
Author

Eu não usaria Invariant e jogaria o erro pra cima no stack até chegar em quem tem capacidade de tratar, se o tratamento for parar que pare.

@andreyvital
Copy link
Contributor

Pelos meus cálculos, o único defer que rola é o que fecha a conexão do cidadão, considerando que falhe uma invariante, vai quitar tudo e de qualquer forma vai desligar o cara, não?

@txgruppi
Copy link
Author

Despende se o Close precisa fazer algo antes de fechar.

@andreyvital
Copy link
Contributor

Pelo visto, nada: https://github.com/gorilla/websocket/blob/master/conn.go#L201-L203. Apenas delega a call pra net.Conn.Close, ao menos aí.

@txgruppi
Copy link
Author

Ainda acho que é melhor "fazer direito"

@andreyvital
Copy link
Contributor

Que saiam os Invariants então!

🍻

@andreyvital andreyvital removed their assignment Apr 30, 2015
@andreyvital andreyvital removed this from the 0.1.0 milestone Apr 30, 2015
@andreyvital andreyvital added this to the 0.1.1 milestone May 2, 2015
@andreyvital andreyvital self-assigned this May 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants