]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blobdiff - t/59-yield-threads.t
Implement yield()
[perl/modules/Scope-Upper.git] / t / 59-yield-threads.t
diff --git a/t/59-yield-threads.t b/t/59-yield-threads.t
new file mode 100644 (file)
index 0000000..fbe054f
--- /dev/null
@@ -0,0 +1,46 @@
+#!perl -T
+
+use strict;
+use warnings;
+
+use lib 't/lib';
+use Scope::Upper::TestThreads;
+
+use Test::Leaner;
+
+use Scope::Upper qw<yield UP>;
+
+our $z;
+
+sub up1 {
+ my $tid  = threads->tid();
+ local $z = $tid;
+ my $p    = "[$tid] up1";
+
+ usleep rand(1e6);
+
+ my @res = (
+  -1,
+  do {
+   my @dummy = (
+    999,
+    map {
+     my $foo = yield $tid .. $tid + 2 => UP;
+     fail "$p: not reached";
+    } 666
+   );
+   fail "$p: not reached";
+  },
+  -2
+ );
+
+ is_deeply \@res, [ -1, $tid .. $tid + 2, -2 ], "$p: yielded correctly";
+}
+
+my @threads = map spawn(\&up1), 1 .. 30;
+
+$_->join for @threads;
+
+pass 'done';
+
+done_testing(scalar(@threads) + 1);