summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Thread/Task/Thread.pm3
-rw-r--r--t/master.t16
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/Thread/Task/Thread.pm b/lib/Thread/Task/Thread.pm
index e922549..2d7880d 100644
--- a/lib/Thread/Task/Thread.pm
+++ b/lib/Thread/Task/Thread.pm
@@ -20,8 +20,7 @@ class Thread::Task::Thread {
my $SINGLETON;
method master(ClassName $class:) {
- $SINGLETON
- or $class->new->spawn;
+ $SINGLETON ||= $class->new->spawn;
}
method import(ClassName $class: @rest) {
diff --git a/t/master.t b/t/master.t
new file mode 100644
index 0000000..1529993
--- /dev/null
+++ b/t/master.t
@@ -0,0 +1,16 @@
+#!perl
+use strict;
+use warnings;
+use Test::Most tests => 4, 'die';
+use threads;
+use Thread::Task::Thread ':master';
+
+sleep 0.1;
+is( scalar( threads->list ), 1, 'One thread exists' );
+
+# Fetch the master, is it the existing one?
+my $master1 = Thread::Task::Thread->master;
+my $master2 = Thread::Task::Thread->master;
+isa_ok( $master1, 'Thread::Task::Thread' );
+isa_ok( $master2, 'Thread::Task::Thread' );
+is( $master1->wid, $master2->wid, 'Masters match' );