NAME

POE::Session::YieldCC - POE::Session extension for using continuations

SYNOPSIS

  use POE::Session::YieldCC;

  POE::Session::YieldCC->create(
    inline_states => {
      handler => sub {
	print "before\n";
	my $val = $_[SESSION]->yieldCC('do_async', 123);
	print "after: $val\n";
      },
      do_async => sub {
        my ($cont, $args) = @_[ARG0, ARG1];
        # do something synchronously, passing $cont about
        # when we're ready:
	$cont->("value");
      },
      demo_sleep => sub {
	print "I feel rather tired now\n";
	$_[SESSION]->sleep(60);
	print "That was a short nap!\n";
      },
    },
  );
  $poe_kernel->run();

DESCRIPTION

POE::Session::YieldCC extends POE::Session to allow "continuations". A new method on the session object, yieldCC is introduced.

yieldCC takes as arguments a state name (in the current session) and a list of arguments. Control is yield to that state (via POE::Session->yield) passing a "continuation" as ARG0 and the arguments as an array reference in ARG1. yieldCC does not return immediately.

The "continuation" is a anonymous subroutine that when invoked passes control back to where yieldCC was called returning any arguments to the continuation from the yieldCC. Once the original state that called yieldCC finishes control returns to where the continuation was invoked.

Examples can be found in the examples/ directory of the distribution.

THIS MODULE IS EXPERIMENTAL. And while I'm pretty sure I've squashed all the memory leaks there may still be some.

METHODS

sleep SECONDS

Takes a number of seconds to sleep for (possibly fraction in the same way that POE::Kernel::delay can take fractional seconds) suspending the current event and only returning after the time has expired. POE events continue to be processed while you're sleeping.

SEE ALSO

POE, POE::Session, Coro::State

AUTHOR

Benjamin Smith <bsmith@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Benjamin Smith

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.