ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.137 by root, Fri Jan 5 10:23:05 2007 UTC vs.
Revision 1.138 by root, Fri Jan 5 17:07:17 2007 UTC

221 # wake up all waiters, to be on the safe side 221 # wake up all waiters, to be on the safe side
222 $_->ready for @{ delete $LOCK{$key} }; 222 $_->ready for @{ delete $LOCK{$key} };
223 } 223 }
224} 224}
225 225
226=item cf::async { BLOCK }
227
228Like C<Coro::async>, but runs the given BLOCK in an eval and only logs the
229error instead of exiting the server in case of a problem.
230
231=cut
232
233sub async(&) {
234 my ($cb) = @_;
235
236 Coro::async {
237 eval { $cb->() };
238 warn $@ if $@;
239 }
240}
241
242sub freeze_mainloop { 226sub freeze_mainloop {
243 return unless $TICK_WATCHER->is_active; 227 return unless $TICK_WATCHER->is_active;
244 228
245 my $guard = Coro::guard { $TICK_WATCHER->start }; 229 my $guard = Coro::guard { $TICK_WATCHER->start };
246 $TICK_WATCHER->stop; 230 $TICK_WATCHER->stop;
272 my $freeze_guard = freeze_mainloop; 256 my $freeze_guard = freeze_mainloop;
273 257
274 my $busy = 1; 258 my $busy = 1;
275 my @res; 259 my @res;
276 260
277 (Coro::async { 261 (Coro::async_pool {
278 @res = eval { $job->() }; 262 @res = eval { $job->() };
279 warn $@ if $@; 263 warn $@ if $@;
280 undef $busy; 264 undef $busy;
281 })->prio (Coro::PRIO_MAX); 265 })->prio (Coro::PRIO_MAX);
282 266
293 } 277 }
294} 278}
295 279
296=item $coro = cf::coro { BLOCK } 280=item $coro = cf::coro { BLOCK }
297 281
298Creates and returns a new coro. This coro is automcatially being canceled 282Creates (and readies) and returns a new coro. This coro is automcatially
299when the extension calling this is being unloaded. 283being canceled when the extension calling this is being unloaded.
300 284
301=cut 285=cut
302 286
303sub coro(&) { 287sub coro(&) {
304 my $cb = shift; 288 my $cb = shift;
305 289
306 my $coro = &cf::async ($cb); 290 my $coro = &Coro::async_pool ($cb);
307 291
308 $coro->on_destroy (sub { 292 $coro->on_destroy (sub {
309 delete $EXT_CORO{$coro+0}; 293 delete $EXT_CORO{$coro+0};
310 }); 294 });
311 $EXT_CORO{$coro+0} = $coro; 295 $EXT_CORO{$coro+0} = $coro;
1555 1539
1556 # try to abort aborted map switching on player login :) 1540 # try to abort aborted map switching on player login :)
1557 # should happen only on crashes 1541 # should happen only on crashes
1558 if ($pl->ob->{_link_pos}) { 1542 if ($pl->ob->{_link_pos}) {
1559 $pl->ob->enter_link; 1543 $pl->ob->enter_link;
1560 cf::async { 1544 Coro::async_pool {
1561 # we need this sleep as the login has a concurrent enter_exit running 1545 # we need this sleep as the login has a concurrent enter_exit running
1562 # and this sleep increases chances of the player not ending up in scorn 1546 # and this sleep increases chances of the player not ending up in scorn
1563 Coro::Timer::sleep 1; 1547 Coro::Timer::sleep 1;
1564 $pl->ob->leave_link; 1548 $pl->ob->leave_link;
1565 }; 1549 };
1574sub cf::object::player::goto { 1558sub cf::object::player::goto {
1575 my ($self, $path, $x, $y) = @_; 1559 my ($self, $path, $x, $y) = @_;
1576 1560
1577 $self->enter_link; 1561 $self->enter_link;
1578 1562
1579 (cf::async { 1563 (Coro::async_pool {
1580 $path = new cf::path $path; 1564 $path = new cf::path $path;
1581 1565
1582 my $map = cf::map::find $path->as_string; 1566 my $map = cf::map::find $path->as_string;
1583 $map = $map->customise_for ($self) if $map; 1567 $map = $map->customise_for ($self) if $map;
1584 1568
1646 1630
1647 return unless $self->type == cf::PLAYER; 1631 return unless $self->type == cf::PLAYER;
1648 1632
1649 $self->enter_link; 1633 $self->enter_link;
1650 1634
1651 (cf::async { 1635 (Coro::async_pool {
1652 $self->deactivate_recursive; # just to be sure 1636 $self->deactivate_recursive; # just to be sure
1653 unless (eval { 1637 unless (eval {
1654 prepare_random_map $exit 1638 prepare_random_map $exit
1655 if $exit->slaying eq "/!"; 1639 if $exit->slaying eq "/!";
1656 1640
1748=cut 1732=cut
1749 1733
1750sub cf::client::coro { 1734sub cf::client::coro {
1751 my ($self, $cb) = @_; 1735 my ($self, $cb) = @_;
1752 1736
1753 my $coro = &cf::async ($cb); 1737 my $coro = &Coro::async_pool ($cb);
1754 1738
1755 $coro->on_destroy (sub { 1739 $coro->on_destroy (sub {
1756 delete $self->{_coro}{$coro+0}; 1740 delete $self->{_coro}{$coro+0};
1757 }); 1741 });
1758 1742

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines