defineEvent Event Execution Path

defineEvent Event Execution Path A sequence diagram generated by Archify. defineEvent({ name, identifier, isNative }) samp.registerEvent(name, identifier) plus samp.on(name, trigger) OnPlayerConnect(playerid) trigger(playerid) beforeEach builds context, then calls the listener return next() advances to the next listener executeAfterEach() runs once after the chain ends transformReturnValue gives 0 or 1, returned via samp-node Register at import Native callback to chain Return value Application script · onConnect listener · Sequence participant Application script onConnect listener @infernus/core bus.ts · eventBus / trigger · Sequence participant @infernus/core bus.ts eventBus / trigger samp-node · samp.on · Sequence participant samp-node samp.on open.mp Server · native callback · Sequence participant open.mp Server native callback Legend request return default message

Registration: an import side effect

  • • defineEvent registers as soon as the module is imported, with no manual init step
  • • With isNative false neither samp.registerEvent nor samp.on is called, making it an in-process custom event
  • • A duplicate name throws CoreException: event [name:xxx] error: already defined

Propagation: next() steers the chain

  • • beforeEach parses native arguments into context; listeners receive { next, defaultValue, ...context }
  • • next(value) advances and Object.assigns value into the shared context, changing what downstream listeners see
  • • Not calling next() halts the chain, and that listener's return value becomes the event result

Return value and errors

  • • The result normalises to 0 or 1: booleans convert, illegal values fall back to defaultValue (1 by default)
  • • A listener returning a Promise does not block the chain; afterEach instead waits on Promise.allSettled
  • • Thrown errors go to setEventErrorHandler, falling back to samp.logprint when unset