184 views
What Go language construct allows executing an action upon exiting a goroutine/function scope?
Asked at
AI answer
It’s defer. It postpones a function call until the current function finishes and executes deferred calls in LIFO order. For example, defer file.Close() is useful for releasing resources. defer does not run simply when exiting an arbitrary scope.
Also asked at WB банк
- [name] talked about implementing 'Teller' — what other interesting tasks were there at previous workplaces?
- So, all four names will work in 10 milliseconds?
- If you look at line 18 (the output of time), what execution time will be displayed there?
- If you output the contents of the map (line 19 in the code) — what will be stored there?
- Clarify: is this a function or a language construct?