GraphQL::PubSub(3pm)
π 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:
- the values of the channel
- the original callback (so you can unsubscribe with it, handy π)
- the exception that was thrown
- 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
- debian bookworm: libgraphql-perl 0.54-1 Β· Artistic-2.0
- debian trixie: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu noble: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu resolute: libgraphql-perl 0.54-1 Β· Artistic-2.0
- ubuntu stonking: libgraphql-perl 0.54-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms