GraphQ...erator(3pm)

πŸ“¦
version 0.54 Β· 2 versions
  • 0.54 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.53 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– GraphQL::AsyncIterator β€” bestie edition πŸ’–

okay so this is GraphQL::AsyncIterator, from the User Contributed Perl Documentation corner of the internet, and it's literally just iterator objects that hand you back a promise for the next result. that's it. that's the whole vibe. πŸ¦‹


✨ NAME ✨

GraphQL::AsyncIterator β€” iterator objects that return a promise to the 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

okay bestie, look at that comment on line 6 β€” yes, it also works when the publish happens before next_p is called. the order is not the moment. we love a flexible queen. πŸ‘‘


πŸŽ€ DESCRIPTION πŸŽ€

so what does this thing even do. it encapsulates all the asynchronous event-handling that the publish/subscribe behaviour needs β€” the stuff that GraphQL::Subscription is out here relying on. it's giving backstage crew energy: you never see it, but nothing runs without it. 🫢


🧚 ATTRIBUTES 🧚

🌈 promise_code

a hash-ref matching "PromiseCode" in GraphQL::Type::Library, which must provide the "new" key. no new key, no deal. that's non-negotiable fr fr. πŸ’€


πŸ’… METHODS πŸ’…

⭐ publish(@values)

resolves the relevant promise with @values. so like, here's your stuff, promise. fulfilled. slay. ✨

πŸ“ error(@values)

rejects the relevant promise with @values. not slay. but sometimes necessary. 😭

πŸ¦‹ next_p

returns either a "Promise" in GraphQL::Type::Library of the next value, or "undef" when it's closed off.

⚠️ do not call this if a previous promised next value has not been settled, because a queue is not maintained. there is no line. there is no waiting room. do not test her. πŸ’€

the promise will have each of the sets of handlers added by "map_then" appended to it. iykyk.

πŸ”₯ close_tap

switch to being closed off. "next_p" will return "undef" as soon as it runs out of "publish"ed values, and "publish" will throw an exception. periodt. doors closed, lights off, we're done here.

NB this will not cause the settling of any outstanding promise returned by "next_p". so like, if there's a promise still out there hanging, it's still hanging. close_tap said nothing about that. mind your business. πŸ™ˆ

πŸŽ€ map_then($then, $catch)

adds the handlers to this object's list of handlers, which will be attached to promises returned by "next_p". returns self, because of course it does, it's generous like that. 🫢


🌸 SEE ALSO 🌸

nothing here, bestie β€” the original didn't list any, and i am not about to invent references. no cap. 🧚


okay that's the whole page!! perl v5.34.0, dated 2022-03-27, and that's your GraphQ...erator moment β€” love that for us. go forth and settle your promises responsibly. mwah πŸ’‹πŸ’–βœ¨

πŸ“¦ where this page comes from