NAME
GraphQL::AsyncIterator - iterator objects that return promise to next result
SYNOPSIS
use GraphQL::AsyncIterator;
my $i = GraphQL::AsyncIterator->new(
promise_code => $pc,
);
# also works when publish happens before next_p called
my $promised_value = $i->next_p;
$i->publish('hi'); # now $promised_value will be fulfilled
$i->close_tap; # now next_p will return undef
DESCRIPTION
Encapsulates the asynchronous event-handling needed for the publish/subscribe behaviour needed by GraphQL::Subscription.
ATTRIBUTES
promise_code
A hash-ref matching "PromiseCode" in GraphQL::Type::Library, which must provide the new
key.
METHODS
publish(@values)
Resolves the relevant promise with @values
.
error(@values)
Rejects the relevant promise with @values
.
next_p
Returns either a "Promise" in GraphQL::Type::Library of the next value, or undef
when closed off. Do not call this if a previous promised next value has not been settled, as a queue is not maintained.
close_tap
Switch to being closed off. "next_p" will return undef
as soon as it runs out of "publish"ed values. "publish" will throw an exception. NB This will not cause the settling of any outstanding promise returned by "next_p".
map_then($then, $catch)
Returns a new object, child of the current one, whose promises will have the supplied then
and catch
handlers attached to promises returned by "next_p".
Values published to the parent object will get propagated to all children. If "close_tap" is called on an object, that will get propagated to all parents and children - this allow a child iterator to be used to communicate the parent iterator should no longer receive values.
If values have already been published into the current object but not read, they will be present in the child, being immediately processed by the handlers.