… | |
… | |
1136 | |
1136 | |
1137 | my $cb = $arg{cb}; |
1137 | my $cb = $arg{cb}; |
1138 | |
1138 | |
1139 | urxvt::timer |
1139 | urxvt::timer |
1140 | ->new |
1140 | ->new |
1141 | ->start (urxvt::NOW + $arg{after}) |
1141 | ->after ($arg{after}) |
|
|
1142 | ->interval ($arg{interval}) |
|
|
1143 | ->start |
1142 | ->cb (sub { |
1144 | ->cb (sub { |
|
|
1145 | #TODO interval? |
1143 | $_[0]->stop; # need to cancel manually |
1146 | $_[0]->stop; # need to cancel manually |
1144 | $cb->(); |
1147 | $cb->(); |
1145 | }) |
1148 | }) |
1146 | } |
1149 | } |
1147 | |
1150 | |
1148 | sub io { |
1151 | sub io { |
1149 | my ($class, %arg) = @_; |
1152 | my ($class, %arg) = @_; |
1150 | |
1153 | |
1151 | my $cb = $arg{cb}; |
1154 | my $cb = $arg{cb}; |
|
|
1155 | my $fd = fileno $arg{fh}; |
|
|
1156 | defined $fd or $fd = $arg{fh}; |
1152 | |
1157 | |
1153 | bless [$arg{fh}, urxvt::iow |
1158 | bless [$arg{fh}, urxvt::iow |
1154 | ->new |
1159 | ->new |
1155 | ->fd (fileno $arg{fh}) |
1160 | ->fd (defined fileno $arg{fh}) |
1156 | ->events (($arg{poll} =~ /r/ ? 1 : 0) |
1161 | ->events (($arg{poll} =~ /r/ ? 1 : 0) |
1157 | | ($arg{poll} =~ /w/ ? 2 : 0)) |
1162 | | ($arg{poll} =~ /w/ ? 2 : 0)) |
1158 | ->start |
1163 | ->start |
1159 | ->cb (sub { |
1164 | ->cb ($cb) |
1160 | $cb->(($_[1] & 1 ? 'r' : '') |
|
|
1161 | . ($_[1] & 2 ? 'w' : '')); |
|
|
1162 | })], |
|
|
1163 | urxvt::anyevent:: |
1165 | ], urxvt::anyevent:: |
|
|
1166 | } |
|
|
1167 | |
|
|
1168 | sub idle { |
|
|
1169 | my ($class, %arg) = @_; |
|
|
1170 | |
|
|
1171 | my $cb = $arg{cb}; |
|
|
1172 | |
|
|
1173 | urxvt::iw |
|
|
1174 | ->new |
|
|
1175 | ->start |
|
|
1176 | ->cb (sub { |
|
|
1177 | #TODO really cancel? |
|
|
1178 | $_[0]->stop; # need to cancel manually |
|
|
1179 | $cb->(); |
|
|
1180 | }) |
|
|
1181 | } |
|
|
1182 | |
|
|
1183 | sub child { |
|
|
1184 | my ($class, %arg) = @_; |
|
|
1185 | |
|
|
1186 | my $cb = $arg{cb}; |
|
|
1187 | |
|
|
1188 | urxvt::pw |
|
|
1189 | ->new |
|
|
1190 | ->start ($arg{pid}) |
|
|
1191 | ->cb (sub { |
|
|
1192 | #TODO really cancel? |
|
|
1193 | $_[0]->stop; # need to cancel manually |
|
|
1194 | $cb->($_[0]->rpid, $_[0]->rstatus); |
|
|
1195 | }) |
1164 | } |
1196 | } |
1165 | |
1197 | |
1166 | sub DESTROY { |
1198 | sub DESTROY { |
1167 | $_[0][1]->stop; |
1199 | $_[0][1]->stop; |
1168 | } |
1200 | } |