… | |
… | |
73 | my $coronew = sub { |
73 | my $coronew = sub { |
74 | # how does one do method-call-by-name? |
74 | # how does one do method-call-by-name? |
75 | # my $w = $class->SUPER::$flavour(@_); |
75 | # my $w = $class->SUPER::$flavour(@_); |
76 | |
76 | |
77 | my $q = new Coro::Channel 0; |
77 | my $q = new Coro::Channel 0; |
|
|
78 | my $w; |
78 | my $w = $new->(@_, cb => sub { $q->put($_[0]) }); |
79 | $w = $new->(@_, parked => 1, cb => sub { $w->stop; $q->put($_[0]) }); |
79 | $w->private($q); # using private as attribute is pretty useless... |
80 | $w->private($q); # using private as attribute is pretty useless... |
80 | bless $w, $class; # reblessing due to broken Event |
81 | bless $w, $class; # reblessing due to broken Event |
81 | }; |
82 | }; |
82 | *{ $flavour } = $coronew; |
83 | *{ $flavour } = $coronew; |
83 | *{"do_$flavour"} = sub { |
84 | *{"do_$flavour"} = sub { |
… | |
… | |
91 | Return the next event of the event queue of the watcher. |
92 | Return the next event of the event queue of the watcher. |
92 | |
93 | |
93 | =cut |
94 | =cut |
94 | |
95 | |
95 | sub next { |
96 | sub next { |
|
|
97 | $_[0]->start; |
96 | $_[0]->private->get; |
98 | $_[0]->private->get; |
97 | } |
99 | } |
98 | |
100 | |
99 | =item Coro::Event->main |
101 | =item Coro::Event->main |
100 | |
102 | |
101 | =cut |
103 | =cut |
102 | |
104 | |
103 | sub main { |
105 | sub main { |
104 | local $Coro::idle = new Coro sub { |
106 | local $Coro::idle = new Coro sub { |
105 | while () { |
|
|
106 | Event::loop(5); |
107 | Event::loop; |
107 | print "in idle loop\n";#d# |
|
|
108 | } |
|
|
109 | }; |
108 | }; |
110 | Coro::schedule; |
109 | Coro::schedule; |
111 | } |
110 | } |
112 | |
111 | |
113 | 1; |
112 | 1; |