Postboy Help

Fire‑and‑Forget Semantics

PostboyGenericMessage represents a one‑way broadcast. The publisher fires a message and continues immediately; subscribers react independently and do not return a value.

1. How it differs from callback messages

Aspect

Generic message

Callback message

Direction

Publisher → Subscribers

Requester → Handler → Requester

Return value

None

Typed result via msg.finish(...)

Lifetime

Delivered to all current subscribers

One handler; one result emission

Contract

class X extends PostboyGenericMessage

class X extends PostboyCallbackMessage<T>

2. The flow

fire(message) → bus → subscriber₁.run(message) → subscriber₂.run(message) → ...

No subscriber is required. If none exist, the message is simply discarded.

3. Code example (framework‑agnostic)

Message definition

import {PostboyGenericMessage} from '@artstesh/postboy'; export class UserLoggedOutEvent extends PostboyGenericMessage { static readonly ID = 'user.logged-out'; constructor(public readonly timestamp: number) { super(); } }

Registration (once, during startup)

import {ConnectMessage} from '@artstesh/postboy'; import {Subject} from 'rxjs'; import {UserLoggedOutEvent} from './user-logged-out.event'; // postboy is an instance of the bus, obtained from your app setup postboy.exec(new ConnectMessage(UserLoggedOutEvent, new Subject<UserLoggedOutEvent>()));

Subscriber (e.g. a cleanup service)

postboy.sub(UserLoggedOutEvent).subscribe((msg) => { console.log(`User logged out at ${new Date(msg.timestamp).toISOString()}`); // clear local cache, reset state });

Subscriber (e.g. a notification service)

postboy.sub(UserLoggedOutEvent).subscribe((msg) => { showToast('Goodbye!'); });

Publisher (e.g. an authentication service)

function onLogout() { postboy.fire(new UserLoggedOutEvent(Date.now())); }

4. No response, no waiting

The publisher does not receive an observable back from fire. The call is synchronous from the publisher’s perspective. Any asynchronous work inside subscribers runs independently.

postboy.fire(new UserLoggedOutEvent(Date.now())); // returns void // publisher moves on immediately

5. When no subscriber exists

Firing a generic message with zero subscribers is a valid, safe operation. The message is discarded, no error is thrown. This makes it safe to publish optional events (e.g., debugging, telemetry) without guarding against empty subscriber lists.

Key points

  • Fire‑and‑forget: the publisher sends the message and forgets about it.

  • No return value: generic messages do not have msg.finish(); they are pure notifications.

  • Decoupling: the publisher never knows how many subscribers exist or what they do.

  • Use for domain events, notifications, state broadcasts — any situation where the publisher does not need a direct answer.

03 мая 2026