Latent Callbacks

Safe Latent Callbacks

This script enables you to make “latent” callbacks, using the Native Trigger(Client/Server)LatentEvent to transfer huge data from server → client and opposite. I also focused on some security features like owner-verfication, no-source-spoofing or duplicate/replay protection via ticket TTL + a few more. You can use it for Data Transfer or simply for your normal callbacks.

Download (GitHub)

API

Register


RegisterCallback(eventName, handler)

  • eventName (string)

  • handler(args)...

args.source is injected (trusted): player id on server, -1 on client.


UnregisterCallback(eventName)

Validated register


RegisterSecureCallback(eventName, validator, handler)

  • validator(args)true or false, "reason" (rejects before handler)

  • handler(args)...

Call (either side)


TriggerCallback(eventName, args?, timeoutSec?, asyncCallback?, method?)

  • args (table) – your data (do not set source)

  • timeoutSec (number) – defaults to lib config (e.g., 30s)

  • asyncCallback (fn) – if given, called as asyncCallback(result..., err)

  • method (“normal” | “latent”) – use "latent" for big payloads

Returns (sync): result... or nil, "error"

Server → specific client


TriggerCallbackFor(playerId, eventName, args?, timeoutSec?, asyncCallback?, method?)

  • Same behavior as TriggerCallback, but targets one playerId (server-only).

Latent shorthand


TriggerLatentCallback(eventName, args?, timeoutSec?, asyncCallback?)

  • Equivalent to TriggerCallback(..., "latent").

More at my GitHub…

Code is accessible Yes
Subscription-based No
Lines (approximately) ~570
Requirements & dependencies NONE
Support Yes
7 Likes

Great job, dude! I found the approach really interesting.

1 Like

Hello! Looks super interesting! If I understand this is useful to optimize also? Or is to load large data without any Wait needed? I was reading the readme and I want test this, but my question was, what this means please?

PLEASE NOTE that when transfering huge payloads the whole server network can freeze, not letting any other event come thru!

And for example this can replace any framework (in my case ESX) callback and optimize them?

1 Like

Hi, thanks for your interest. Firstly no… this script is not meant to optimize anything or reduce load time but to enable the use of latent events in callbacks because without the latent method events return a error when trying to pass huge data. With the warning I was trying to say that when you for example transfer a audio file as raw base64 data, wich will be a huge string often many kilobytes long, the network can be busy transferring the string to its destination resulting in blockage for other events, meaning that no other events, for your case important esx events, come through.
Surely you can use my code to implement the latent method into the esx callbacks but I’m not positive that it will optimize them in any way. :smile:

1 Like