4 ms·
Ehm, not sure I understood, but I'd say no. Defer is just code that is executed in reverse order upon return from a fuction. It has nothing to do with coroutine
by dullgiulio 9y ago
Ehm, not sure I understood, but I'd say no. Defer is just code that is executed in reverse order upon return from a fuction. It has nothing to do with coroutines. It's a cleaner way to write the usual C syntax of "goto cleanup_x" code.
Go coroutines (goroutines) are functions invoked with the "go" keyword. These cannot be stopped or resumed, but might be (possibly) executed on a different thread. In any case, they are not guaranteed to be executed immediately in the normal flow of the code.
- coldtea 9y ago>Ehm, not sure I understood, but I'd say no. Defer is just code that is executed in reverse order upon return from a fuction. I'd say more like the equivalent of a "finally" clause (or more) for your whole function. Though not sure about the "executed in reverse order part" -- what's "in reverse order" about Defer? Except if you mean that multiple defers get executed "last seen first"...
- 19eightyfour 9y agoThanks alot for explaining, I think i get it a bit better now.