Skip to main content

Interface: CustomSlotSupplier<SI>

worker.CustomSlotSupplier

The interface can be implemented to provide custom slot supplier behavior.

Type parameters

NameType
SIextends SlotInfo

Properties

type

type: "custom"

Methods

markSlotUsed

markSlotUsed(slot): void

This function is called once a slot is actually being used to process some task, which may be some time after the slot was reserved originally. For example, if there is no work for a worker, a number of slots equal to the number of active pollers may already be reserved, but none of them are being used yet. This call should be non-blocking.

Parameters

NameType
slotSlotMarkUsedContext<SI>

Returns

void


releaseSlot

releaseSlot(slot): void

This function is called once a permit is no longer needed. This could be because the task has finished, whether successfully or not, or because the slot was no longer needed (ex: the number of active pollers decreased). This call should be non-blocking.

Parameters

NameType
slotSlotReleaseContext<SI>

Returns

void


reserveSlot

reserveSlot(ctx, abortSignal): Promise<SlotPermit>

This function is called before polling for new tasks. Your implementation should block until a slot is available then return a permit to use that slot.

The only acceptable exception to throw is AbortError, any other exceptions thrown will be logged and ignored.

The value inside the returned promise should be an object, however other types will still count as having issued a permit. Including undefined or null. Returning undefined or null does not mean you have not issued a permit. Implementations are expected to block until a meaningful permit can be issued.

Parameters

NameTypeDescription
ctxSlotReserveContextThe context for slot reservation.
abortSignalAbortSignalThe SDK may decide to abort the reservation request if it's no longer needed. Implementations may clean up and then must reject the promise with AbortError.

Returns

Promise<SlotPermit>

A permit to use the slot which may be populated with your own data.


tryReserveSlot

tryReserveSlot(ctx): null | SlotPermit

This function is called when trying to reserve slots for "eager" workflow and activity tasks. Eager tasks are those which are returned as a result of completing a workflow task, rather than from polling. Your implementation must not block, and if a slot is available, return a permit to use that slot.

Parameters

NameTypeDescription
ctxSlotReserveContextThe context for slot reservation.

Returns

null | SlotPermit

Maybe a permit to use the slot which may be populated with your own data.