Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Focus on promises rather than condvars.

  • Loading branch information...
commit 7f5d4db10cc950e22658392aeee4f9ff891bab1c 1 parent 2fe7ce2
@rcaputo authored
View
6 eg/eg-33-all-callbacks.pl
@@ -120,9 +120,9 @@
my $rh = RoleHandler->new();
-### Poll for events with a condvar-like promise construct. Goes last
-### because the while() loop will "block". Meanwhile, next() is also
-### allowing the other timers to run.
+### Poll for events with promises. Goes last because the while() loop
+### will "block". Meanwhile, next() is also allowing the other timers
+### to run.
my $pt = Reflex::Timer->new(
interval => 1 + rand(),
View
10 lib/Reflex.pm
@@ -45,7 +45,7 @@ Reflex - Class library for flexible, reactive programs.
=head1 SYNOPSIS
# See eg-18-synopsis-no-moose.pl if you don't like Moose.
- # See eg-32-promise-tiny.pl if you prefer condvars.
+ # See eg-32-promise-tiny.pl if you prefer promises (condvar-like).
# See eg-36-coderefs-tiny.pl if you prefer coderefs and/or closures.
{
@@ -164,11 +164,11 @@ decided upon.
A complete, runnable version of the above example is available as
eg/eg-36-tiny-coderefs.pl in the distribution.
-=head2 Condvars Instead of Callbacks
+=head2 Promises Instead of Callbacks
Callback haters are not left out. Reflex objects may also be used as
-condvars. The following example is identical in function to the
-previous coderef callback example, but it doesn't use callbacks at
+inline promises. The following example is identical in function to
+the previous coderef callback example, but it doesn't use callbacks at
all.
It may not be obvious, but the same emit() method drives all of
@@ -224,7 +224,7 @@ Reflex bundles a number of helpful base classes to get things started.
Reflex::Callback - base class for Reflex callbacks
| Reflex::Callback::CodeRef - simple coderef callback adapter
| Reflex::Callback::Method - adapts callbacks to methods
- | Reflex::Callback::Promise - adapts callbacks to condvars
+ | Reflex::Callback::Promise - adapts callbacks to promises (condvar-like)
Reflex::POE::Event - represents POE events in Reflex
Reflex::POE::Postback - represents POE postbacks in Reflex
Reflex::Trait::EmitsOnChange - emit events when a member's value changes
View
31 lib/Reflex/Callback/Promise.pm
@@ -34,7 +34,7 @@ __END__
=head1 NAME
-Reflex::Callback::Promise - Condvar-like non-callback adapter
+Reflex::Callback::Promise - Non-callback, inline Promise adapter
=head1 SYNOPSIS
@@ -64,10 +64,31 @@ Low-level usage:
=head1 DESCRIPTION
-Reflex::Callback::Promise maps the generic Reflex::Callback interface
-to non-callback promises, which are kind of like condvars. In most
-cases, Reflex::Callbacks' cb_promise() or other syntactic sweeteners
-will be used instead of raw Reflex::Callback::Promise objects.
+"In computer science, future, promise, and delay refer to constructs
+used for synchronization in some concurrent programming languages.
+They describe an object that acts as a proxy for a result that is
+initially not known, usually because the computation of its value has
+not yet completed." --
+http://en.wikipedia.org/wiki/Promise_%28programming%29
+
+Reflex::Callback::Promise enables Reflex objects to be used as inline
+event streams. Reflex::Callback::Promise and Reflex::Role::Reactive
+transparently handle the conversion. Reflex objects do not need
+special code to be used this way.
+
+In most cases, Reflex::Callbacks::cb_promise() or other syntactic
+sweeteners will be used instead of raw Reflex::Callback::Promise
+objects. For example, promises are implicitly enabled if no callbacks
+are defined:
+
+ my $t = Reflex::Timer->new(
+ interval => 1,
+ auto_repeat => 1,
+ );
+
+ while (my $event = $t->next()) {
+ print "next() returned an event\n";
+ }
=head2 new
View
10 lib/Reflex/Callbacks.pm
@@ -343,11 +343,11 @@ cb_promise() takes a scalar reference. This reference will be
populated with a Reflex::Callback::Promise object.
cb_promise() returns two values that are suitable to insert onto a
-Reflex::Base's constructor. The first value is a special event
-name, "on_promise", that tells Reflex::Base objects they may be used
-as promises or in a condvar-like context. The second return value is
-the same Reflex::Callback::Promise object that was inserted into
-cb_promise()'s parameter.
+Reflex::Base's constructor. The first value is a special event name,
+"on_promise", that tells Reflex::Base objects they may be used inline
+as promises. The second return value is the same
+Reflex::Callback::Promise object that was inserted into cb_promise()'s
+parameter.
use Reflex::Callbacks qw(cb_promise);
my $promise;
View
2  lib/Reflex/Client.pm
@@ -122,7 +122,7 @@ eg/eg-35-tcp-client.pl available at the time of this writing.
Reflex::Client is a high-level base class for non-blocking socket
clients. As with other Reflex::Base classes, this one may be
-subclassed, composed with "has", or driven with condvar-like syntax.
+subclassed, composed with "has", or driven inline with promises.
=head2 Attributes
View
8 lib/Reflex/Connector.pm
@@ -126,8 +126,8 @@ source for a more complete example.
$self->stop();
}
-Reflex objects may also be used in condvar-like ways. This excerpts
-from eg/eg-38-promise-client.pl in the distribution.
+Reflex objects may also be used as promises. This excerpts from
+eg/eg-38-promise-client.pl in the distribution.
my $connector = Reflex::Connector->new(remote_port => 12345);
my $event = $connector->next();
@@ -209,8 +209,8 @@ It will return a "socket", the value of which is the connected socket.
L<Reflex::Client> extends Reflex::Connector to include a
Reflex::Stream when the socket is connected.
-eg/eg-38-promise-client.pl shows how to use Reflex::Connector in a
-condvar-like fashion.
+eg/eg-38-promise-client.pl shows how to use Reflex::Connector may be
+used as a promise.
=head1 SEE ALSO
Please sign in to comment.
Something went wrong with that request. Please try again.