Examples

Page 27 of 50

Browse code examples

goSnippet

Sort Map Entries By Value

Maps have no order, so copy entries into a slice and sort with SortFunc by value descending, using the key as a tiebreak for a stable ranked report.

goSnippet

Nil Map Reads Versus Writes

Show which nil map operations are safe — len and comma-ok lookup — and which one panics on assignment, then allocate with make before writing.

goSnippet

Timer Reset Rearms Idle Timeouts

Reuse one time.Timer across select iterations by stopping, draining, and resetting it, so the idle timeout renews after every event without new allocations.

goSnippet

WaitGroup Wait With A Timeout

Convert wg.Wait into a channel receive so select can race completion against a deadline, and see that timed-out workers keep running without one.

javaSnippet

CompletableFuture Callback Bridge

Complete a hand-built CompletableFuture from a legacy callback thread so listener APIs join async pipelines; late duplicate callbacks cannot rewrite the result.