The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

GraphQL::PubSub - publish/subscribe

SYNOPSIS

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

DESCRIPTION

Encapsulates the publish/subscribe logic needed by GraphQL::Subscription.

METHODS

subscribe($channel, \&callback[, \&error_callback])

Registers the given callback on the given channel.

The optional second "error" callback is called as a method on the object when an exception is thrown by the first callback. If not given, the default is for the subscription to be cancelled with "unsubscribe". The error callback will be called with values of the channel, the original callback (to enable unsubscribing), the exception thrown, then the values passed to the original callback. Any exceptions will be ignored.

unsubscribe($channel, \&callback)

Removes the given callback from the given channel.

publish($channel, @values)

Calls each callback registered on the given channel, with the given values.