howmanysmall / Janitor

Janitor library.
https://howmanysmall.github.io/Janitor/
MIT License
105 stars 18 forks source link

Call functions added for cleanup in a new coroutine #23

Closed ghost closed 2 years ago

ghost commented 2 years ago

Currently, my janitor functions yield like so:

janitor:Add(function()
    -- some yielding operation
end)

This causes other cleanup methods to be delayed of course which isn't expected behavior, and I and (mostly no-one) wants to go through the headache of handling these yielding operations in a new thread just because of how Janitor works.

OverHash commented 2 years ago

This behavior was introduced in an older version of Janitor, and in my opinion it masks the true behaviour of cleanups. Cleanup operations should be non-yielding, it doesn't really make sense to have a cleanup operation that takes time. Handling the threading yourself, rather than Janitor doing it for you makes a lot more sense to me. This is especially true now that it's quite primitive to do tasks in Luau,

janitor:Add(function()
    task.spawn(function()
        -- some yielding operation
    end)
end)
ghost commented 2 years ago

I agree, I just realized this was a minor design flow within how I control my cleanup tasks.