… | |
… | |
33 | |
33 | |
34 | BEGIN { |
34 | BEGIN { |
35 | eval "use Time::HiRes 'time'"; |
35 | eval "use Time::HiRes 'time'"; |
36 | } |
36 | } |
37 | |
37 | |
38 | $VERSION = 1.6; |
38 | $VERSION = 1.7; |
39 | @EXPORT_OK = qw(timeout sleep); |
39 | @EXPORT_OK = qw(timeout sleep); |
40 | |
40 | |
41 | =item $flag = timeout $seconds; |
41 | =item $flag = timeout $seconds; |
42 | |
42 | |
43 | This function will wake up the current coroutine after $seconds |
43 | This function will wake up the current coroutine after $seconds |
… | |
… | |
73 | sub bool { |
73 | sub bool { |
74 | !${${$_[0]}} |
74 | !${${$_[0]}} |
75 | } |
75 | } |
76 | |
76 | |
77 | sub DESTROY { |
77 | sub DESTROY { |
78 | ${${$_[0]}}->cancel; |
78 | ${${$_[0]}}->cancel if ${${$_[0]}}; |
79 | undef ${${$_[0]}}; # without this it leaks like hell. breaks the circular reference inside the closure |
79 | undef ${${$_[0]}}; # without this it leaks like hell. breaks the circular reference inside the closure |
80 | } |
80 | } |
81 | |
81 | |
82 | use overload 'bool' => \&bool, '0+' => \&bool; |
82 | use overload 'bool' => \&bool, '0+' => \&bool; |
83 | |
83 | |