QubicTypeScript

subscribeNewTicks

Emits a notification on every new tick as an AsyncIterable of SubscriptionEvent.

Signature

bob.subscribeNewTicks(options?: SubscribeOptions): AsyncIterable<SubscriptionEvent<BobTickNotification>>

Purpose

Emits a notification on every new tick. No historical replay.

import { createBobClient } from "@qubic.org/bob"

const bob = createBobClient({ baseUrl: "http://localhost:40420" })
const ac = new AbortController()

for await (const event of bob.subscription.subscribeNewTicks({ signal: ac.signal })) {
  const { tick, epoch } = event.data
  console.log(`Tick ${tick} in epoch ${epoch}`)
}

Parameters

NameTypeDescription
options.signalAbortSignalStops the iteration when aborted

Returns

AsyncIterable<SubscriptionEvent<BobTickNotification>>

Every SubscriptionEvent has this shape:

interface SubscriptionEvent<T> {
  data: T             // the event payload
  isCatchUp: boolean  // true for historical events delivered after reconnect
  logId?: bigint      // log ID (present on log and transfer events)
  tick?: number       // tick number (present on some events)
}

BobTickNotification fields

FieldTypeDescription
data.ticknumberCurrent tick number
data.epochnumberCurrent epoch number

Stopping a subscription

Pass an AbortSignal to stop without closing the entire client.

const ac = new AbortController()

setTimeout(() => ac.abort(), 30_000) // stop after 30 seconds

for await (const event of bob.subscription.subscribeNewTicks({ signal: ac.signal })) {
  console.log(event.data.tick)
}
// loop ends when signal is aborted

To stop all subscriptions at once, call bob.subscription.close().

On this page