Skip to main content
Latest
interface UpdateSink
Re-export
import { type UpdateSink } from "https://deno.land/x/grammy_runner@v2.0.3/mod.ts";

An update sink is an object that acts as the sink for updates for a runner. It features a handle function that takes in a batch of updates in the form of an array. It returns a promise that should resolve with a positive integral number soon as the sink is ready to handle further updates. The resolved number indicates how many updates the sink is ready to handle next.

Note that calles might not guarantee that this constraint is respected. While update sinks can use this mechanism to signal backpressure to the caller, it should be able to queue up update internally if the underlying sink cannot handle updates as rapidly as they are being supplied.

Properties

handle: (updates: Y[]) => Promise<number>

Handles a batch of updates in the form of an array. Resolves with an integral number of updates that the update sink can handle, as soon as this value is positive.

size: () => number

Returns the size of the sink. The size is equal to the number of tasks that are currently being processed. Calling size() is always equal to snapshot().length.

snapshot: () => Y[]

Takes a snapshot of the sink. This synchronously returns all tasks that are currently being processed, in the order they were added.

In the context of grammY, this can be useful if the runner must be terminated gracefully but shall not wait for the middleware to complete, for instance because some middleware performs long-running operations. You can then store the updates in order to process them again if desired, without losing data.