Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

Idiom #185 Execute function in 30 seconds

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

import "time"
go func() {
	time.Sleep(30 * time.Second)
	f(42)
}()

The code after the goroutine launch executes immediately.

Consider adding proper synchronization where needed. Data races are forbidden!
import "time"
timer := time.AfterFunc(
	30*time.Second,
	func() {
		f(42)
	})

f is wrapped in an anonymous func having 0 arg and 0 return value.

The timer instance can be used to cancel the call.
(do (Thread/sleep 30000)
    (f 42))

Clojure is a hosted language, and relies on host interop for things like this

New implementation...
< >
programming-idioms.org