function call onto a list. The list of saved calls is executed after the surrounding function returns. Defer is commonly used to simplify functions that perform various clean-up actions. Deferred function calls are executed in Last In First Out order after the surrounding function returns. • Ref: https://go.dev/blog/defer-panic-and-recover • 11 ݴޠػೳඪ४ύοέʔδʹ͋ΔΫϦʔϯΞοϓػߏ defer
call on [Server.Shutdown]. This can be used to gracefully shutdown connections that have undergone ALPN protocol upgrade or that have been hijacked. This function should start protocol-specific graceful shutdown, but should not wait for shutdown to complete. • Ref: https://github.com/golang/go/blob/adbfb672ba485630d75f8b5598228a63f4af08a4/src/ net/http/server.go#L2985-L2994 • 14 ݴޠػೳඪ४ύοέʔδʹ͋ΔΫϦʔϯΞοϓػߏ func (*Server) RegisterOnShutdown
function to be called when the test (or subtest) and all its subtests complete. Cleanup functions will be called in last added, first called order. • Ref: https://github.com/golang/go/blob/adbfb672ba485630d75f8b5598228a63f4af08a4/src/ testing/testing.go#L1151-L1153 17 ݴޠػೳඪ४ύοέʔδʹ͋ΔΫϦʔϯΞοϓػߏ func (*T) Cleanup
operate independently; one does not replace another. (ུ) The stop function does not wait for f to complete before returning. If the caller needs to know whether f is completed, it must coordinate with f explicitly. • Ref: https://github.com/golang/go/blob/adbfb672ba485630d75f8b5598228a63f4af08a4/src/ context/context.go#L297-L314 • 20 ݴޠػೳඪ४ύοέʔδʹ͋ΔΫϦʔϯΞοϓػߏ func AfterFunc(ctx Context, f func()) (stop func() bool)
transaction to context.Context when the context is canceled. • https://github.com/k1LoW/donegroup • طଘίʔυͰൖ͍ͤͯ͞Δcontext.ContextΛͬͯύοέʔδؔΛԣஅͨ͠τϥϯβΫ γϣϯʢಛʹॲཧͷྃͷཧʣΛఏڙ͢ΔύοέʔδͰ͢ɻ • ඪ४ύοέʔδͷΈͰ࣮͍ͯ͠ΔͷͰZero dependency 34 ఏҊख๏ donegroup