Logo

Programming-Idioms

History of Idiom 185 > diff from v1 to v2

Edit summary for version 2 by programming-idioms.org:
New Go implementation by user [programming-idioms.org]

Version 1

2019-09-09, 08:45:10

Version 2

2019-09-09, 08:55:59

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
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
Demo URL
https://play.golang.org/p/X8Bvs1m1bD5