use v6;
use Test;
plan 17;
my $timestamp = time;
async {
ok 1, 'async call started';
};
my $async_duration = time - $timestamp;
$timestamp = time;
my $thr = async {
sleep .1;
};
ok time - $timestamp < $async_duration + .5, "yes, 'Im out of sync!";
ok ~$thr, 'stringify a thread';
ok +$thr, 'numerify a thread should be the thread id';
isnt +$thr, $*PID, 'childs id is not parents thread id';
ok $thr.join, 'thread now joined and back home';
sub do_something_very_important {
return 1;
}
my @threads;
@threads[0] = async { ok do_something_very_important(),'very important things from first thread' };
@threads[1] = async { ok do_something_very_important(),'very important things from second thread' };
ok @threads[0].join,'first thread joined';
ok @threads[1].join,'second thread joined';
ok eval q{#!@threads[1].join},'second thread not joinable again';
@threads[2] = async { ok do_something_very_important(),'again start a thread' };
ok eval q{threads[2].detach},'detach a thread';
ok !@threads[2].join,'could not join a detached thread';
@threads[3] = async { ok do_something_very_important(),'another thread' };
ok eval q{@threads[3].suspend},' send him back to a waiting room..';
ok eval q{@threads[3].resume},'... now he is back';