class MQTT::Pending(T)

Overview

A single-shot slot for a response we're expecting from the broker.

This replaces the promises that used to carry request/response plumbing. Promise::DeferredPromise#get spawns a fiber and allocates a channel on every call, and Promise.timeout costs another fiber and channel per request. More importantly a promise runs its callbacks inline on whichever fiber resolves it, which made it unsafe to resolve one while holding a lock.

Completion is signalled by closing a channel, which wakes every waiter rather than handing the value to whoever happens to receive first.

Defined in:

mqtt/pending.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def completed? : Bool #

[View source]
def get(timeout : Time::Span | Nil = nil, description : String = "response") : T #

Blocks the calling fiber until the response arrives. Raises MQTT::TimeoutError if timeout elapses first.


[View source]
def reject(error : Exception) : Nil #

[View source]
def resolve(value : T) : Nil #

[View source]