Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 120 lines (85 sloc) 2.103 kb
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
1 Documenting Reflex syntax evolution.
2
3 =head1 Gathering callbacks.
4
1f5ed27 @rcaputo Rename Reflex::Role::Object to Reflex::Role::Reactive; Reflex::Object…
authored
5 Reflex::Role::Reactive
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
6 Has the cb() member.
7 BUILD
8 Maps constructor parameters to callbacks.
5f9458c @rcaputo Rename observe() to watch(). Rename wait() to next().
authored
9 Maps callback types to watchers:
10 discrete callbacks = discrete watchers
11 role callbacks = role watchers
12 no callbacks = unwatched (promise?)
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
13
1f5ed27 @rcaputo Rename Reflex::Role::Object to Reflex::Role::Reactive; Reflex::Object…
authored
14 =head1 Reflex::Role::Reactive::BUILD calls cb_gather()
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
15
16 emit() syntax is preserved.
1f5ed27 @rcaputo Rename Reflex::Role::Object to Reflex::Role::Reactive; Reflex::Object…
authored
17 1. Role::Reactive handles it normally.
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
18 2. Local delivery is through the callback object.
19
20 $self->emit( event => \%args );
21
22 =head1 Callback constructor parameter.
23
24 =cut
25
bbf149d @rcaputo Create Reflex::Role::Interval, and reify it as Reflex::Interval. Nee…
authored
26 my $timer = Reflex::Interval->new(
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
27 interval => 5,
28 auto_repeat => 1,
29 on_tick => cb_coderef(\&subroutine),
30 );
31
bbf149d @rcaputo Create Reflex::Role::Interval, and reify it as Reflex::Interval. Nee…
authored
32 my $timer = Reflex::Interval->new(
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
33 interval => 5,
34 auto_repeat => 1,
35 on_tick => cb_method($self, "method"),
36 );
37
bbf149d @rcaputo Create Reflex::Role::Interval, and reify it as Reflex::Interval. Nee…
authored
38 my $timer = Reflex::Interval->new(
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
39 interval => 5,
40 auto_repeat => 1,
41 on_tick => cb_method("class", "method"),
42 );
43
44 =head1 Role constructor parameter.
45
46 =cut
47
bbf149d @rcaputo Create Reflex::Role::Interval, and reify it as Reflex::Interval. Nee…
authored
48 my $timer = Reflex::Interval->new(
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
49 interval => 5,
50 auto_repeat => 1,
51 cb_role($self, "rolename"),
52 );
53
54 =head1 Promise.
55
56 =cut
57
bbf149d @rcaputo Create Reflex::Role::Interval, and reify it as Reflex::Interval. Nee…
authored
58 my $timer = Reflex::Interval->new(
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
59 interval => 5,
60 auto_repeat => 1,
61 # cb_promise
62 );
63
5f9458c @rcaputo Rename observe() to watch(). Rename wait() to next().
authored
64 while (my $event = $timer->next()) {
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
65 ...;
66 }
67
5f9458c @rcaputo Rename observe() to watch(). Rename wait() to next().
authored
68 =head1 Watcher.
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
69
70 =cut
71
bbf149d @rcaputo Create Reflex::Role::Interval, and reify it as Reflex::Interval. Nee…
authored
72 my $timer = Reflex::Interval->new(
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
73 interval => 5,
74 auto_repeat => 1,
75 promise => 1,
76 );
77
5f9458c @rcaputo Rename observe() to watch(). Rename wait() to next().
authored
78 $self->watch(
79 watcher => $timer,
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
80 event => "tick",
81 callback => ANY_RCB_EXCEPT_PROMISE,
82 );
83
84 =head1 Promise Again
85
86 The current syntax is too verbose.
87
5f9458c @rcaputo Rename observe() to watch(). Rename wait() to next().
authored
88 $watcher has no purpose except to call watch().
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
89
5f9458c @rcaputo Rename observe() to watch(). Rename wait() to next().
authored
90 Perhaps $watcher could be replaced by a Promise class that watches
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
91 and then returns events? Similar to PromiseThing in
92 eg-25-rcb-promise.pl?
93
94 =cut
95
96 #!/usr/bin/env perl
97
98 use warnings;
99 use strict;
100
101 use lib qw(../lib);
102
bbf149d @rcaputo Create Reflex::Role::Interval, and reify it as Reflex::Interval. Nee…
authored
103 use Reflex::Interval;
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
104 use Reflex::Callbacks qw(cb_promise);
105 use ExampleHelpers qw(eg_say);
106
1f5ed27 @rcaputo Rename Reflex::Role::Object to Reflex::Role::Reactive; Reflex::Object…
authored
107 my $watcher = Reflex::Base->new();
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
108
109 my $promise;
bbf149d @rcaputo Create Reflex::Role::Interval, and reify it as Reflex::Interval. Nee…
authored
110 my $timer = Reflex::Interval->new(
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
111 interval => 1,
112 auto_repeat => 1,
113 );
114
5f9458c @rcaputo Rename observe() to watch(). Rename wait() to next().
authored
115 $watcher->watch($timer, cb_promise(\$promise));
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
116
5f9458c @rcaputo Rename observe() to watch(). Rename wait() to next().
authored
117 while (my $event = $promise->next()) {
118 eg_say("next() returned an event (@$event)");
0d58684 @rcaputo Get promises working. Use Reflex::Timer with a promise.
authored
119 }
Something went wrong with that request. Please try again.