-- Compiled with roblox-ts v2.0.4 local PROVIDER_KEY = "__proton_provider__" local started = false local awaitStartThreads = {} local awaitCallbacks = {} --[[ * * Provider decorator. ]] local function Provider() return function(providerClass) if started then error("[Proton]: Cannot create provider after Proton has started", 2) end providerClass[PROVIDER_KEY] = providerClass.new() end end local Proton = {} do local _container = Proton --[[ * * Start Proton. This should only be called once per * environment (e.g. once on the server and once on * the client). Attempts to call this more than once * will throw an error. * * If any providers yield within their constructors, * then this method will also yield. * * ```ts * Proton.start(); * print("Proton started"); * ``` ]] local function start() if started then return nil end started = true for _, callback in awaitCallbacks do task.spawn(callback) end for _, awaitThread in awaitStartThreads do task.spawn(awaitThread) end table.clear(awaitCallbacks) table.clear(awaitStartThreads) end _container.start = start --[[ * * Yields the calling thread until Proton has been * fully started. * * ```ts * Proton.awaitStart(); * print("Started"); * ``` ]] local function awaitStart() if started then return nil end local thread = coroutine.running() table.insert(awaitStartThreads, thread) coroutine.yield() end _container.awaitStart = awaitStart --[[ * * Calls the callback once Proton has fully started. * If Proton is already started, the callback will * be spawned immediately. * @param callback Callback ]] local function onStart(callback) if started then task.spawn(callback) return nil end local _callback = callback table.insert(awaitCallbacks, _callback) end _container.onStart = onStart --[[ * * Gets a provider within Proton. * * An error will be thrown if the provider does not * exist. * * ```ts * // Directly * const myProvider = Proton.get(MyProvider); * * // From another provider * class AnotherProvider { * private readonly myProvider = Proton.get(MyProvider); * } * ``` * * @param providerClass The provider class * @returns The provider singleton object ]] local function get(providerClass) local provider = providerClass[PROVIDER_KEY] if provider == nil then error('[Proton]: Failed to find provider "' .. (tostring(providerClass) .. '"'), 2) end return provider end _container.get = get end return { Provider = Provider, Proton = Proton, }