Logo

Programming-Idioms

History of Idiom 185 > diff from v6 to v7

Edit summary for version 7 by programming-idioms.org:
[Go] Comment was... lost?!

Version 6

2019-09-09, 09:01:38

Version 7

2019-09-09, 09:05:01

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
import  "time"
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