Skip to content

Commit

Permalink
Move classes outside of REACT sub
Browse files Browse the repository at this point in the history
That pattern caused some pain with `SUPPLY` before now.
  • Loading branch information
jnthn committed Sep 19, 2017
1 parent 9e17935 commit c46be84
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions src/core.d/await.pm
Expand Up @@ -53,40 +53,41 @@ my role X::React::Died {
}
}

sub REACT(&block --> Nil) {
my class ReactAwaitable does Awaitable {
has $!handle;

method new($handle) {
self.CREATE!set-handle($handle)
}
method !set-handle($handle) {
$!handle = $handle;
self
}
my class Rakudo::Internals::ReactAwaitable does Awaitable {
has $!handle;

method get-await-handle() { $!handle }
method new($handle) {
self.CREATE!set-handle($handle)
}
method !set-handle($handle) {
$!handle = $handle;
self
}
my class ReactAwaitHandle does Awaitable::Handle {
has &!react-block;

method not-ready(&react-block) {
self.CREATE!set-react-block(&react-block)
}
method !set-react-block(&react-block) {
&!react-block = &react-block;
self
}
method get-await-handle() { $!handle }
}
my class Rakudo::Internals::ReactAwaitHandle does Awaitable::Handle {
has &!react-block;

method subscribe-awaiter(&subscriber) {
SUPPLY(&!react-block).tap:
{ warn "Useless use of emit in react" },
done => { subscriber(True, Nil) },
quit => { subscriber(False, $_) };
}
method not-ready(&react-block) {
self.CREATE!set-react-block(&react-block)
}
method !set-react-block(&react-block) {
&!react-block = &react-block;
self
}

method subscribe-awaiter(&subscriber) {
SUPPLY(&!react-block).tap:
{ warn "Useless use of emit in react" },
done => { subscriber(True, Nil) },
quit => { subscriber(False, $_) };
}
}
sub REACT(&block --> Nil) {
CATCH {
($_ but X::React::Died(Backtrace.new(5))).rethrow
}
$*AWAITER.await(ReactAwaitable.new(ReactAwaitHandle.not-ready(&block)));
$*AWAITER.await(Rakudo::Internals::ReactAwaitable.new(
Rakudo::Internals::ReactAwaitHandle.not-ready(&block)));
}

0 comments on commit c46be84

Please sign in to comment.