Does Coroutine.Yield effect the Logic of Require?

Hello! I’ve been working on a new/updated version for my Framework, And when requiring the Module. It seems to yield the script for an infinite amount of time?

Require > Init > Promise [ Client is Syncing with Server Framework] > Require is infinitely yielding?

Here, My Code in case the above didn’t make any sense. [ Very likely ]
My Module Script (The End/Focus Bit.)

-- // Base Infinity Constructor
-- @About: The method which constructs a new Infinity Object.
function Infinity.new()
    local self = setmetatable({ }, Infinity)

    self.IsStudio = RunService:IsStudio()
    self.IsServer = RunService:IsServer()

    self.ClassManager = require(script.ClassManager)
    self.LibaryManager = require(script.LibaryManager)

    self.Wrapper = require(script.InfinityWrapper)

    self.LibaryManager:Export(self)
    return self.Wrapper:Complete(self) -- This `Complete` function synces and builds the system.
end

return Infinity.new()

This complete uses a Promise, This promise is a result of InvokeServer, As shown below.

local Stream = Base.Net.new("SyncStream")
        local Promise = Stream:InvokeStream()

        Promise:Then(function(ServerSyncPacket)
            local Classes = ServerSyncPacket.Classes

            warn("Got:", ServerSyncPacket)

            for _, ClassName in ipairs(Classes) do
                -- Base.NetworkClass:Extend(ClassName)
            end
        end):Catch(function(Exception)
            warn(("Server-Sync Error: %s"):format(Exception))
            task.wait(.5)

            Promise:Retry()
        end):Await()
        -- Calling Await on this thread is the method doing coroutine.yield

And finally, the source script.

-- // Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- // Variables
local Infinity = require(ReplicatedStorage:WaitForChild("Infinity"))
warn("Required!") -- Never gets to this point, however it does finish/return in the module.

So here I am, Stumped on weather this is some internal/engine bug or am I missing an obvious piece of logic?

To make a replica of this, without all the clutter. This is essentially an example.

task.delay(2, coroutine.resume, coroutine.running(), { })

return coroutine.yield()

^ Throw that in a module, then require it.

2 Likes

Well, I found a hacky-like way to get around this. You’ll have to declare a Watchdog-Like variable and use task.wait to pause the execution, Coroutine library is being a little bit weird with the Require Logic.

local Watchdog = false

task.delay(5, function() Watchdog = true end)

repeat task.wait() until Watchdog

^ This would yield a Module. However, Coroutine.Yield will not.

1 Like