Logo

Programming-Idioms

History of Idiom 185 > diff from v20 to v21

Edit summary for version 21 by gpvos:
New Perl implementation by user [gpvos]

Version 20

2019-09-27, 10:36:55

Version 21

2020-04-29, 10:01:14

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
use threads;
Code
my $thr = threads->create(sub { sleep(10); f(42); });
$thr->detach();   # Alternatively, use $thr->join() to wait for it to finish
Comments bubble
Uses Perl 5.6 threads. If the main function exits without having join()ed the thread, the thread will be killed.
Doc URL
https://perldoc.perl.org/threads.html