Tutorial by Examples

A defer statement in Go is simply a function call marked to be executed at a later time. Defer statement is an ordinary function call prefixed by the keyword defer. defer someFunction() A deferred function is executed once the function that contains the defer statement returns. Actual call to th...
Deferred function calls serve a similar purpose to things like finally blocks in languages like Java: they ensure that some function will be executed when the outer function returns, regardless of if an error occurred or which return statement was hit in cases with multiple returns. This is useful f...

Page 1 of 1