class GraphQL::Broadcast(T)

Overview

Fans values out to any number of subscribers, each receiving them on its own channel. Meant for subscription resolvers: a mutation publishes, and a subscription field returns #subscribe.

MESSAGES = GraphQL::Broadcast(Message).new

@[GraphQL::Field]
def message_added : Channel(Message)
  MESSAGES.subscribe
end

Every subscriber channel buffers buffer values. A subscriber that has not drained its buffer misses the next value rather than blocking the publisher and every other subscriber. Closed channels are dropped on the next publish.

Defined in:

graphql/broadcast.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(buffer : Int32 = 16) #

Instance Method Detail

def close : Nil #

def publish(value : T) : Nil #

def size : Int32 #

Number of open subscriber channels.


def subscribe : Channel(T) #

def unsubscribe(channel : Channel(T)) : Nil #