Events

The events plugin carries temporary messages and request/response exchanges between the callers of one open database. Use it to tell a live consumer that facts changed, to wake a worker, or to exchange streaming results without writing a fact for each message. Enable it at open with plugins {events {}}. It has no settings. See plugin selection for the open options.

Follow Checkers with the events plugin for a runnable progression through pub/sub, request, pull, push and duplex.

Events are not database state. A publication or an exchange message never enters the store, and commits never publish an event. The plugin does not retry, acknowledge or replay a message. Record anything that must survive as facts first, then publish an event that tells consumers to read those facts. Only definitions of publication subjects and exchange routes are stored. Events travel inside the process through the C API and the bindings; they use no network.

Owners

A caller opens an event owner with open_owner. Subscriptions, worker registrations and exchange sides belong to the owner that created them. Only that owner may use or end them; another owner's id reports wrong_owner. close_owner ends everything the owner holds and cancels its exchanges: each other party reads a cancel notice. Closing the database closes every owner and interrupts waiting calls with closed.

Publish and subscribe

A publisher sends one native value to a literal subject with publish. A subject is a non-empty, slash-separated name with no empty segment, such as orders/created. Publishing needs no owner, and a publication with no matching subscriber succeeds.

An owner starts a subscription with subscribe. Its pattern is a regular expression that Stardust anchors to the complete subject. Thus orders/.* matches orders/created, while created does not.

The owner pulls events with receive, which waits up to maxWait. A subscription queues at most 1024 events or 8 MB, and queued bytes count against the database memory budget. When a queue is full, or the budget refuses a delivery, Stardust drops that delivery without delaying the publisher or other subscribers. The publisher learns the number of deliveries and drops from the result of publish. A subscription reports the deliveries it missed in the dropped member of the event it returns next. A publication holds at most 1 MB of data.

unsubscribe ends a subscription and drops its queued events.

Exchanges

An exchange connects one caller to one worker. A worker registers a mode and a subject pattern with register. A caller opens that mode on a literal subject with call. The registration with the lowest id among the matches serves the call, and a call with no matching worker reports no_worker.

ModeCaller sendsWorker sends
requestOne request, as data of the callOne response
pushA stream, then finishOne response, after the caller finished
pullOne request, as data of the callA stream, then finish
duplexA stream, then finishA stream, then finish

The worker takes the next exchange with accept, which returns the worker side's handle and, for request and pull, the request. Each side sends with send, tells the other party it sent everything with finish, and reads with read. read returns a message, a finish or a cancel notice. Finishing closes only the finishing side's sending direction, so it can still read.

cancel ends the exchange at once, and the other party reads cancel. Closing either owner cancels the exchange. Unregistering a worker cancels its exchanges that are still waiting for acceptance. Exchanges that the worker already accepted continue after unregistering. Each side queues at most 1024 messages or 8 MB against the memory budget; a send that does not fit reports delivery_failed and cancels the exchange, because dropping a message would corrupt it. A completed or cancelled exchange leaves its sides readable until their queues drain, then they disappear.

Definitions

A stored definition of the event type fixes the request and response of a route. Write it with patch_definition under the events kind at <mode>/<route>, for example request/orders/create. Its document holds a JSON Schema for each direction:

123 B
{request {type object required [customer] properties {customer {type string}}}
 response {type object required [accepted]}}

The first path segment is the mode, which fixes who may stream. Use {} for a direction that carries any value. A call with a definition checks its request, and every later message of the exchange against the schemas as they were when the call opened. A message that breaks its schema reports invalid_payload and leaves the exchange running. A route without a definition is unchecked. Definitions are ordinary stored definitions: history, backups and restores carry them. A database that stores an event definition refuses to open without the events plugin, so its contracts cannot be skipped. The SDK generation plugin renders typed publish, subscribe, caller and worker code for the stored routes in each language's output folder.

A publication definition lives at publish/<subject>, for example publish/orders/created. Its document is the payload schema:

62 B
type object
required [order]
properties {order {type integer}}

Each publication uses the subject's current schema before it changes any subscriber queue. Invalid data reports invalid_payload, including when there are no subscribers. Subjects without definitions remain unchecked. Generated publish and subscribe helpers bind the subject and payload type; subscriptions match the exact subject. Event results preserve empty objects and arrays inside payloads.

Runtime status

Call status to inspect these fields:

FieldContents
ownersOpen owners
subscriptionsOpen subscriptions
registrationsWorker registrations
rpcsLive exchanges
queuedItems waiting in all queues

Operations

OperationReturnsSummary
events_statusdocumentevents.status() returns the event runtime's owned status document.
events_open_ownerdocumentevents.open_owner() opens an event owner and returns an owned document with its id.
events_close_ownernoneevents.close_owner(owner) ends everything an owner holds and cancels its exchanges.
events_publishdocumentevents.publish(event) delivers one temporary message to every matching subscription and returns an owned count document.
events_subscribedocumentevents.subscribe(owner, pattern) starts a subscription of an owner and returns an owned document with its id.
events_receivedocumentevents.receive(options) returns the oldest queued event of a subscription as an owned document.
events_unsubscribenoneevents.unsubscribe(owner, subscription) ends a subscription and drops its queued events.
events_registerdocumentevents.register(owner, mode, pattern) registers an owner as a worker for exchanges and returns an owned document with the registration id.
events_unregisternoneevents.unregister(owner, registration) ends a worker registration.
events_acceptdocumentevents.accept(options) takes the oldest waiting exchange of a registration and returns an owned document describing it.
events_calldocumentevents.call(request) opens an exchange with the earliest matching worker and returns an owned document with the caller side's handle.
events_sendnoneevents.send(request) sends one message on an exchange side to the other party.
events_finishnoneevents.finish(owner, handle) ends the sending direction of an exchange side.
events_cancelnoneevents.cancel(owner, handle) cancels an exchange and drops the caller's side.
events_readdocumentevents.read(options) returns the oldest notice of an exchange side as an owned document.

events_status

odin98 B
events_status :: proc(
	db: Database,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

The document counts owners, subscriptions, registrations, exchanges and queued items: see runtime status.

Examples

Count owners, subscriptions and queued items

odin76 B
result := stardust.events_status(db) or_return
defer stardust.close(&result)
Result / 89 B
{
  "owners": 0,
  "subscriptions": 0,
  "registrations": 0,
  "rpcs": 0,
  "queued": 0
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_open_owner

odin102 B
events_open_owner :: proc(
	db: Database,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

Subscriptions, registrations and exchange sides belong to an owner. See owners.

Examples

Open an event owner

odin80 B
result := stardust.events_open_owner(db) or_return
defer stardust.close(&result)
Result / 16 B
{
  "owner": 1
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_close_owner

odin107 B
events_close_owner :: proc(
	db: Database,
	owner: builtin.i64,
	allocator := context.allocator,
) -> Error

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
ownerbuiltin.i64ValueRequiredThe owner that opened it, from open_owner.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentthe request is not an object with only an integer owner
.Not_Foundthe owner does not exist or ended
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed

Examples

Close an owner and everything it holds

odin123 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
stardust.events_close_owner(db, 1) or_return

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_publish

odin117 B
events_publish :: proc(
	db: Database,
	event: Document,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
eventDocumentBorrowed for the callRequiredA borrowed object {subject data}. subject is a literal subject; data is any native value.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentevent is not an object with exactly subject and data, the subject is malformed (code invalid_subject), or data exceeds 1 MB (code too_large)
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

A publication is never stored or replayed. See publishing.

Examples

Publish a temporary message

odin368 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_subscribe(db, 1, "orders/.*") or_return
defer stardust.close(&step2)
doc3 := stardust.parse(`{subject orders/created data {order 42}}`, .DUST) or_return
defer stardust.close(&doc3)
result := stardust.events_publish(db, doc3) or_return
defer stardust.close(&result)
Result / 36 B
{
  "delivered": 1,
  "dropped": 0
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_subscribe

odin140 B
events_subscribe :: proc(
	db: Database,
	owner: builtin.i64,
	pattern: string,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
ownerbuiltin.i64ValueRequiredThe owner that opened it, from open_owner.
patternstringValueRequiredA regular expression for the complete subject.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentthe request is malformed, or the pattern is empty or not a valid regular expression (code invalid_pattern)
.Not_Foundthe owner does not exist
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

A pattern is a regular expression anchored to the complete subject. See subscriptions.

Examples

Subscribe to every order subject

odin174 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
result := stardust.events_subscribe(db, 1, "orders/.*") or_return
defer stardust.close(&result)
Result / 23 B
{
  "subscription": 2
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_receive

odin119 B
events_receive :: proc(
	db: Database,
	options: Document,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
optionsDocumentBorrowed for the callAbsent selects operation defaultsA borrowed object {owner subscription maxWait}. maxWait is an optional nonnegative native duration.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentoptions is not an object with owner and subscription (integers) and optionally a valid maxWait, or the subscription belongs to another owner (code wrong_owner)
.Not_Foundthe owner or the subscription does not exist
.TimeoutmaxWait passed before an event arrived
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

receive waits up to maxWait. Without it the call checks once and reports timeout when no event is queued.

Examples

Receive the oldest queued event

odin566 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_subscribe(db, 1, "orders/.*") or_return
defer stardust.close(&step2)
doc3 := stardust.parse(`{subject orders/created data {order 42}}`, .DUST) or_return
defer stardust.close(&doc3)
step3 := stardust.events_publish(db, doc3) or_return
defer stardust.close(&step3)
doc4 := stardust.parse(`{owner 1 subscription 2 maxWait {#dur PT1S}}`, .DUST) or_return
defer stardust.close(&doc4)
result := stardust.events_receive(db, doc4) or_return
defer stardust.close(&result)
Result / 99 B
{
  "subject": "orders/created",
  "sequence": 1,
  "dropped": 0,
  "data": {
    "order": 42
  }
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_unsubscribe

odin135 B
events_unsubscribe :: proc(
	db: Database,
	owner: builtin.i64,
	subscription: builtin.i64,
	allocator := context.allocator,
) -> Error

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
ownerbuiltin.i64ValueRequiredThe owner that opened it, from open_owner.
subscriptionbuiltin.i64ValueRequiredThe id subscribe returned.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentthe request is malformed, or the subscription belongs to another owner (code wrong_owner)
.Not_Foundthe owner or the subscription does not exist or ended
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed

Examples

End a subscription

odin220 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_subscribe(db, 1, "orders/.*") or_return
defer stardust.close(&step2)
stardust.events_unsubscribe(db, 1, 2) or_return

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_register

odin154 B
events_register :: proc(
	db: Database,
	owner: builtin.i64,
	mode: string,
	pattern: string,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
ownerbuiltin.i64ValueRequiredThe owner that opened it, from open_owner.
modestringValueRequiredrequest, push, pull or duplex.
patternstringValueRequiredA regular expression for the complete subject.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentthe request is malformed, the mode is unknown (code invalid_mode) or the pattern is empty or invalid (code invalid_pattern)
.Not_Foundthe owner does not exist
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

The earliest matching registration serves each call. See exchanges.

Examples

Register an owner as a worker

odin184 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
result := stardust.events_register(db, 1, "request", "orders/.*") or_return
defer stardust.close(&result)
Result / 23 B
{
  "registration": 2
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_unregister

odin134 B
events_unregister :: proc(
	db: Database,
	owner: builtin.i64,
	registration: builtin.i64,
	allocator := context.allocator,
) -> Error

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
ownerbuiltin.i64ValueRequiredThe owner that opened it, from open_owner.
registrationbuiltin.i64ValueRequiredThe id register returned.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentthe request is malformed, or the registration belongs to another owner (code wrong_owner)
.Not_Foundthe owner or the registration does not exist
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed

Examples

End a worker registration

odin229 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_register(db, 1, "request", "orders/.*") or_return
defer stardust.close(&step2)
stardust.events_unregister(db, 1, 2) or_return

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_accept

odin118 B
events_accept :: proc(
	db: Database,
	options: Document,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
optionsDocumentBorrowed for the callAbsent selects operation defaultsA borrowed object {owner registration maxWait}. maxWait is an optional nonnegative native duration.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentoptions is not an object with owner and registration (integers) and optionally a valid maxWait, or the registration belongs to another owner (code wrong_owner)
.Not_Foundthe owner or the registration does not exist
.TimeoutmaxWait passed before an exchange arrived
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

accept waits up to maxWait. The result carries the worker side's handle: see exchanges.

Examples

Take the oldest waiting exchange as the worker

odin675 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_open_owner(db) or_return
defer stardust.close(&step2)
step3 := stardust.events_register(db, 2, "request", "orders/.*") or_return
defer stardust.close(&step3)
doc4 := stardust.parse(`{owner 1 mode request subject orders/create data {customer Ada}}`, .DUST) or_return
defer stardust.close(&doc4)
step4 := stardust.events_call(db, doc4) or_return
defer stardust.close(&step4)
doc5 := stardust.parse(`{owner 2 registration 3 maxWait {#dur PT1S}}`, .DUST) or_return
defer stardust.close(&doc5)
result := stardust.events_accept(db, doc5) or_return
defer stardust.close(&result)
Result / 119 B
{
  "handle": 6,
  "rpc": 4,
  "mode": "request",
  "subject": "orders/create",
  "data": {
    "customer": "Ada"
  }
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_call

odin116 B
events_call :: proc(
	db: Database,
	request: Document,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
requestDocumentBorrowed for the callRequiredA borrowed object {owner mode subject data}.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentrequest is malformed, the mode or subject is invalid (codes invalid_mode and invalid_subject), data is missing for request or pull, present for push or duplex, or exceeds 1 MB, or data does not match the stored request schema (code invalid_payload)
.Not_Foundthe owner does not exist, or no registered worker matches (code no_worker)
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

A stored definition for the route checks every message. See exchanges and definitions.

Examples

Open a request exchange with a worker

odin478 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_open_owner(db) or_return
defer stardust.close(&step2)
step3 := stardust.events_register(db, 2, "request", "orders/.*") or_return
defer stardust.close(&step3)
doc4 := stardust.parse(`{owner 1 mode request subject orders/create data {customer Ada}}`, .DUST) or_return
defer stardust.close(&doc4)
result := stardust.events_call(db, doc4) or_return
defer stardust.close(&result)
Result / 29 B
{
  "handle": 5,
  "rpc": 4
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_send

odin99 B
events_send :: proc(
	db: Database,
	request: Document,
	allocator := context.allocator,
) -> Error

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
requestDocumentBorrowed for the callRequiredA borrowed object {owner handle data}.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentrequest is malformed, the side may not send now (code wrong_direction), the handle belongs to another owner (code wrong_owner), or data does not match its schema (code invalid_payload)
.Not_Foundthe owner or the side does not exist, or the exchange ended and the side drained
.Conflictthe side already finished (code already_finished), or the other party's queue is full (code delivery_failed)
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed

Notes

A message is checked against the stored schemas of its route. See exchanges.

Examples

Answer a request as the worker

odin805 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_open_owner(db) or_return
defer stardust.close(&step2)
step3 := stardust.events_register(db, 2, "request", "orders/.*") or_return
defer stardust.close(&step3)
doc4 := stardust.parse(`{owner 1 mode request subject orders/create data {customer Ada}}`, .DUST) or_return
defer stardust.close(&doc4)
step4 := stardust.events_call(db, doc4) or_return
defer stardust.close(&step4)
doc5 := stardust.parse(`{owner 2 registration 3}`, .DUST) or_return
defer stardust.close(&doc5)
step5 := stardust.events_accept(db, doc5) or_return
defer stardust.close(&step5)
doc6 := stardust.parse(`{owner 2 handle 6 data {accepted true}}`, .DUST) or_return
defer stardust.close(&doc6)
stardust.events_send(db, doc6) or_return

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_finish

odin124 B
events_finish :: proc(
	db: Database,
	owner: builtin.i64,
	handle: builtin.i64,
	allocator := context.allocator,
) -> Error

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
ownerbuiltin.i64ValueRequiredThe owner that opened it, from open_owner.
handlebuiltin.i64ValueRequiredThe side handle: from call for the caller, from accept for the worker.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentthe request is malformed, the side cannot finish in this mode (code wrong_direction), or the handle belongs to another owner (code wrong_owner)
.Not_Foundthe owner or the side does not exist
.Conflictthe side already finished (code already_finished), or the other party's queue is full (code delivery_failed)
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed

Examples

Finish the caller's stream

odin490 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_open_owner(db) or_return
defer stardust.close(&step2)
step3 := stardust.events_register(db, 2, "push", "uploads/.*") or_return
defer stardust.close(&step3)
doc4 := stardust.parse(`{owner 1 mode push subject uploads/a}`, .DUST) or_return
defer stardust.close(&doc4)
step4 := stardust.events_call(db, doc4) or_return
defer stardust.close(&step4)
stardust.events_finish(db, 1, 5) or_return

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_cancel

odin124 B
events_cancel :: proc(
	db: Database,
	owner: builtin.i64,
	handle: builtin.i64,
	allocator := context.allocator,
) -> Error

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
ownerbuiltin.i64ValueRequiredThe owner that opened it, from open_owner.
handlebuiltin.i64ValueRequiredThe side handle: from call for the caller, from accept for the worker.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentthe request is malformed, or the handle belongs to another owner (code wrong_owner)
.Not_Foundthe owner or the side does not exist
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed

Examples

Cancel an exchange

odin490 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_open_owner(db) or_return
defer stardust.close(&step2)
step3 := stardust.events_register(db, 2, "push", "uploads/.*") or_return
defer stardust.close(&step3)
doc4 := stardust.parse(`{owner 1 mode push subject uploads/a}`, .DUST) or_return
defer stardust.close(&doc4)
step4 := stardust.events_call(db, doc4) or_return
defer stardust.close(&step4)
stardust.events_cancel(db, 1, 5) or_return

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

events_read

odin116 B
events_read :: proc(
	db: Database,
	options: Document,
	allocator := context.allocator,
) -> (
	Document,
	Error,
)

Parameters

ParameterTypeOwnershipDefaultMeaning
dbDatabaseBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
optionsDocumentBorrowed for the callAbsent selects operation defaultsA borrowed object {owner handle maxWait}. maxWait is an optional nonnegative native duration.
allocatormem.AllocatorValuecontext.allocatorAllocator for copied return values and diagnostics. The caller releases them with the same allocator.

Errors

StatusWhen
.Invalid_Argumentoptions is not an object with owner and handle (integers) and optionally a valid maxWait, or the handle belongs to another owner (code wrong_owner)
.Not_Foundthe owner or the side does not exist, or it drained after the exchange ended
.TimeoutmaxWait passed before a notice arrived
.Unavailablethe database does not enable the events plugin
.Closedthe database is closed
.Out_Of_Memorynative memory is exhausted

Notes

A message, the other party's finish or a cancel arrives as kind message, finish or cancel.

Examples

Read the worker's response

odin996 B
step1 := stardust.events_open_owner(db) or_return
defer stardust.close(&step1)
step2 := stardust.events_open_owner(db) or_return
defer stardust.close(&step2)
step3 := stardust.events_register(db, 2, "request", "orders/.*") or_return
defer stardust.close(&step3)
doc4 := stardust.parse(`{owner 1 mode request subject orders/create data {customer Ada}}`, .DUST) or_return
defer stardust.close(&doc4)
step4 := stardust.events_call(db, doc4) or_return
defer stardust.close(&step4)
doc5 := stardust.parse(`{owner 2 registration 3}`, .DUST) or_return
defer stardust.close(&doc5)
step5 := stardust.events_accept(db, doc5) or_return
defer stardust.close(&step5)
doc6 := stardust.parse(`{owner 2 handle 6 data {accepted true}}`, .DUST) or_return
defer stardust.close(&doc6)
stardust.events_send(db, doc6) or_return
doc7 := stardust.parse(`{owner 1 handle 5 maxWait {#dur PT1S}}`, .DUST) or_return
defer stardust.close(&doc7)
result := stardust.events_read(db, doc7) or_return
defer stardust.close(&result)
Result / 61 B
{
  "kind": "message",
  "data": {
    "accepted": true
  }
}

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release