Logo

Programming-Idioms

History of Idiom 185 > diff from v4 to v5

Edit summary for version 5 by programming-idioms.org:
[Go] import "time"

Version 4

2019-09-09, 09:00:38

Version 5

2019-09-09, 09:00:54

Idiom #185 Execute function in 30 seconds

Schedule the execution of f(42) in 30 seconds.

Idiom #185 Execute function in 30 seconds

Schedule the execution of f(42) in 30 seconds.

Extra Keywords
future
Extra Keywords
future
Imports
Imports
import  "time"
Code
timer := time.AfterFunc(
	30*time.Second,
	func() {
		f(42)
	})
Code
timer := time.AfterFunc(
	30*time.Second,
	func() {
		f(42)
	})
Comments bubble
f is wrapped in an anonymous func having 0 arg and 0 return value.

The timer instance can be used to cancel the call.
Doc URL
https://golang.org/pkg/time/#AfterFunc
Doc URL
https://golang.org/pkg/time/#AfterFunc
Demo URL
https://play.golang.org/p/X8Bvs1m1bD5
Demo URL
https://play.golang.org/p/X8Bvs1m1bD5