Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
(do (Thread/sleep 30000)
(f 42))
Clojure is a hosted language, and relies on host interop for things like this
sleep(30*1000)
f(42)
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.schedule(() -> _f(42), delayInSeconds, TimeUnit.SECONDS);
Thread t = new Thread(() -> {
try {
sleep(30_000);
f(42);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
t.start();
my $thr = threads->create(sub { sleep(30); f(42); });
$thr->join()
join() waits for $thr to finish
my $thr = threads->create(sub { sleep(30); f(42); });
$thr->detach();
Uses Perl 5.6 threads. Note that if the main program exits without having join()ed the thread, the thread will be killed.
local $SIG{ALRM} = sub { f(42) };
alarm 30;
Attach a handler to an alarm signal. Then ask the OS to deliver the signal in thirty seconds. NOTE: can handle only one delayed task at a time.
Thread.new do
sleep 30
f(42)
end
(f future: 30 "seconds" * 1000) value: 42.
- #value executes a BlockClosure
- #future: delays the next message send to the object by the specified time in milliseconds
- #future: delays the next message send to the object by the specified time in milliseconds