GraphQL::PubSub(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::PubSub β€” the perl doc you needed, bestie πŸ’–

okay so welcome to GraphQL::PubSub(3pm), a User Contributed Perl Documentation moment. it's giving pub/sub, it's giving channels, it's giving callbacks. let's get into it 🫢


✨ NAME ✨

GraphQL::PubSub β€” publish/subscribe, but make it a module πŸ’…


🌸 SYNOPSIS 🌸

here's the vibe, literally copy-paste this energy:

use GraphQL::PubSub;
my $pubsub = GraphQL::PubSub->new;
$pubsub->subscribe('channel1', \&callback);
$pubsub->publish('channel1', 1);
$pubsub->unsubscribe('channel1', \&callback);

that's it. that's the whole main character arc. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically this module encapsulates the publish/subscribe logic that GraphQL::Subscription needs. it's the little helper doing the behind-the-scenes work so subscriptions can go off. no cap, that's literally its whole job. ✨


πŸŽ€ METHODS πŸŽ€


πŸ’œ subscribe($channel, &callback[, &error_callback])

registers the given callback on the given channel. simple as. πŸ“

the optional second "error" callback? okay so here's the tea: it gets called as a method on the object whenever an exception gets thrown by the first callback. 😭

if you don't give one, the default behavior is that the subscription gets cancelled with unsubscribe. so it just… dips. gone. cancelled. πŸ’€

when the error callback does get called, it's handed, in this exact order:

  1. the values of the channel
  2. the original callback (so you can unsubscribe with it, handy πŸ‘€)
  3. the exception that was thrown
  4. then the values that were passed to the original callback

and any exceptions from all of that? ignored. fully ignored. we don't acknowledge them. πŸ™ˆ


🌈 unsubscribe($channel, &callback)

removes the given callback from the given channel. that's it, that's the method. bye bestie πŸ‘‹


⭐ publish($channel, @values)

calls every callback registered on the given channel, passing along the given values. blast it out to everyone subscribed, no thoughts, just publishing. πŸ”₯


heads up bestie: the error callback is called as a method on the object, not as a plain function β€” don't forget that part, iykyk πŸ’…

and that's the whole page, fr fr. this iconic little doc is GraphQL::PubSub(3pm) from perl v5.34.0, dated 2022-03-27 β€” User Contributed Perl Documentation, ate and left no crumbs πŸ§šπŸ’–βœ¨

πŸ“¦ where this page comes from