Please enable JavaScript.
Coggle requires JavaScript to display documents.
Golang (Control Flow (defer (pushes the function call into a LIFO stack,…
Golang
Control Flow
defer
pushes the function call into a LIFO stack, and later execute it before calling function returns
-
-
-
panic
-
-
-
keep returning until all functions in current goroutine have returned, then the program crashes
recover
-
-
When panicking, capture the value passed to panic and resume normal execution
Otherwise, a call to recover returns nil and have no other effect
select
default
non-blocking select, exit select immediately if no other channel is ready
-
-
Concurrency
-
Goroutine
:!: goroutines are NOT GC'ed, MUST exit on their own
Context
a type that contains values shared within a transaction/context, and having the same lifecycle
Data Structures
Channel
-
Receive from a closed channel always proceeds immediately, yielding the zero value of the element's type
:!: beware of zero values of primitive types like false, 0, etc.:star: use closing channel as broadcasting signal to consumers of the channel here