From 5fbfb025a8f9720b13545bf447a3e78f49869b0b Mon Sep 17 00:00:00 2001 From: Stephen Leitnick Date: Mon, 6 Jan 2020 00:26:29 -0500 Subject: [PATCH] Migrate from FastSpawn module to Thread module --- .../Aero/Internal/FastSpawn.lua | 49 ------------------- .../Aero/Internal/AeroServer.server.lua | 9 ++-- .../Aero/Internal/AeroClient.client.lua | 9 ++-- 3 files changed, 8 insertions(+), 59 deletions(-) delete mode 100644 src/ReplicatedStorage/Aero/Internal/FastSpawn.lua diff --git a/src/ReplicatedStorage/Aero/Internal/FastSpawn.lua b/src/ReplicatedStorage/Aero/Internal/FastSpawn.lua deleted file mode 100644 index f8ed98c..0000000 --- a/src/ReplicatedStorage/Aero/Internal/FastSpawn.lua +++ /dev/null @@ -1,49 +0,0 @@ ---[[ - - MIT License - - Copyright (c) 2014 Quenty - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - --]] - --- FastSpawn --- Quenty --- December 23, 2017 --- Original source: https://github.com/Quenty/NevermoreEngine/blob/version2/Modules/Utility/fastSpawn.lua - - ---- An expensive way to spawn a function. However, unlike spawn(), it executes on the same frame, and --- unlike coroutines, does not obscure errors --- @module fastSpawn - -return function(func, ...) - - assert(type(func) == "function") - - local args = {...} - local bindable = Instance.new("BindableEvent") - bindable.Event:Connect(function() - func(unpack(args)) - end) - - bindable:Fire() - bindable:Destroy() - -end \ No newline at end of file diff --git a/src/ServerScriptService/Aero/Internal/AeroServer.server.lua b/src/ServerScriptService/Aero/Internal/AeroServer.server.lua index a6fb57b..f3fa6d3 100644 --- a/src/ServerScriptService/Aero/Internal/AeroServer.server.lua +++ b/src/ServerScriptService/Aero/Internal/AeroServer.server.lua @@ -15,7 +15,6 @@ local mt = {__index = AeroServer} local servicesFolder = game:GetService("ServerStorage").Aero.Services local modulesFolder = game:GetService("ServerStorage").Aero.Modules local sharedFolder = game:GetService("ReplicatedStorage").Aero.Shared -local internalFolder = game:GetService("ReplicatedStorage").Aero.Internal local remoteServices = Instance.new("Folder") remoteServices.Name = "AeroRemoteServices" @@ -23,7 +22,7 @@ remoteServices.Name = "AeroRemoteServices" local players = {} local modulesAwaitingStart = {} -local FastSpawn = require(internalFolder.FastSpawn) +local SpawnNow = require(sharedFolder.Thread:Clone()).SpawnNow local function PreventEventRegister() error("Cannot register event after Init method") @@ -117,7 +116,7 @@ function AeroServer:WrapModule(tbl) if (modulesAwaitingStart) then modulesAwaitingStart[#modulesAwaitingStart + 1] = tbl else - FastSpawn(tbl.Start, tbl) + SpawnNow(tbl.Start, tbl) end end end @@ -196,7 +195,7 @@ local function StartService(service) -- Start services on separate threads: if (type(service.Start) == "function") then - FastSpawn(service.Start, service) + SpawnNow(service.Start, service) end end @@ -289,7 +288,7 @@ local function Init() -- Start modules that were already loaded: local function StartLoadedModules() for _,tbl in pairs(modulesAwaitingStart) do - FastSpawn(tbl.Start, tbl) + SpawnNow(tbl.Start, tbl) end modulesAwaitingStart = nil end diff --git a/src/StarterPlayer/StarterPlayerScripts/Aero/Internal/AeroClient.client.lua b/src/StarterPlayer/StarterPlayerScripts/Aero/Internal/AeroClient.client.lua index 5b06607..eda2634 100644 --- a/src/StarterPlayer/StarterPlayerScripts/Aero/Internal/AeroClient.client.lua +++ b/src/StarterPlayer/StarterPlayerScripts/Aero/Internal/AeroClient.client.lua @@ -17,11 +17,10 @@ local mt = {__index = Aero} local controllersFolder = script.Parent.Parent:WaitForChild("Controllers") local modulesFolder = script.Parent.Parent:WaitForChild("Modules") local sharedFolder = game:GetService("ReplicatedStorage"):WaitForChild("Aero"):WaitForChild("Shared") -local internalFolder = game:GetService("ReplicatedStorage").Aero:WaitForChild("Internal") local modulesAwaitingStart = {} -local FastSpawn = require(internalFolder:WaitForChild("FastSpawn")) +local SpawnNow = require(sharedFolder:WaitForChild("Thread"):Clone()).SpawnNow local function PreventEventRegister() error("Cannot register event after Init method") @@ -61,7 +60,7 @@ function Aero:WrapModule(tbl) if (modulesAwaitingStart) then modulesAwaitingStart[#modulesAwaitingStart + 1] = tbl else - FastSpawn(tbl.Start, tbl) + SpawnNow(tbl.Start, tbl) end end end @@ -149,7 +148,7 @@ end local function StartController(controller) -- Start controllers on separate threads: if (type(controller.Start) == "function") then - FastSpawn(controller.Start, controller) + SpawnNow(controller.Start, controller) end end @@ -209,7 +208,7 @@ local function Init() -- Start modules that were already loaded: local function StartLoadedModules() for _,tbl in pairs(modulesAwaitingStart) do - FastSpawn(tbl.Start, tbl) + SpawnNow(tbl.Start, tbl) end modulesAwaitingStart = nil end