With coroutine.resume being replaced with task.spawn, there is no reason for it to still be used.
Deprecation in this case is especially important because coroutine.resume can lead to incredibly hard to debug problems. A lot of time could be saved if upon using coroutine.resume, the function would be barred with the tooltip saying to use task.spawn instead.
coroutine.resume and task.spawn serve entirely different purposes and there are still genuine cases where one would want to manage their own threads outside the task scheduler, such as custom generators and state machines.
Even if mixing the coroutine and task library together leads to confusing behavior, the solution to that is better documentation, not deprecating things.
coroutine.resume will likely lead to module loading issues. If you use it for custom generators and state machines you’re setting yourself up for bugs straight from hell.
Roblox stated that their solution to this was the task scheduler.
The task library does not give you any information on thread state or yield/return values, as its only purpose is scheduling. It is not a comprehensive replacement for the coroutine library and nowhere has Roblox endorsed that mindset. Even the task library documentation tells you to consult with the coroutine library for advanced cases.
As I’ve said, just because improper use of coroutine.resume can lead to confusing bugs does not justify deprecating it. Lots of stuff in programming can cause issues if used wrongly. There are genuine cases where one would need to handle their own coroutines, and your lack of awareness is no excuse for dismissing them.
Are you AI generating your responses? You seem to lack coherence.
The task library does not replace the coroutine library, no one made that statement. “nowhere has roblox endorsed that mindset” I guess you’re just missing that in your dataset my artificially intelligent friend. here you go
Task.spawn succesfully replaces coroutine.resume, and coroutine.resume specifically has issues. There is no further reason to use it and your lack of awareness is no excuse for not deprecating it.
coroutine.resume will never be deprecated. The task library is not part of the standard Luau library. The task library is specific to Roblox. The coroutine library is part of Luau.
This might be just the dumbest feature request I have ever heard.
Should we deprecate scripts as a whole because they can be misused? Obviously, no.
I still use coroutine.resume regularly; in fact I use it at the start of almost every script:
Just because it doesn’t fit your use cases doesn’t mean it fits nobody’s use cases.
Man I really hope you get the worst of glitches because of this, y’all have no sense of practicality. If coroutine.resume is in all sense and purpose a worse task.spawn, then good practice should point to the ideal function being called
Why would I care that you use it at the start of your scripts? Who the hell cares? You’re some random writing bad code and using functions that ROBLOX THEMSELVES have told not to use, you proved nothing.
How can you even come in here calling a reasonable feature request dumb and provide nothing but “No cause I use it” when all evidence points to the fact that you absolutely shouldn’t?
What the hell is wrong with you man, fix your brain.
What is this some kind of appeal to authority? it being in the standard lua library does not mean anything. setfenv is in the standard lua library and yet you should never ever use it in roblox.
What are these points man you guys give me an headache
task.spawn and coroutine.resume have different purposes. task.spawn is a simpler way to use coroutines that don’t provide any way of closing/resuming functions/tasks created with it. coroutine allow for more advanced usage and more control over what you are doing. you can get the state of coroutines, suspend them, resume them and stop them.
And before you say that having multiple different ways of doing the same thing is bad, consider languages like C++, which have a similar system. It has numerous features that allow you to accomplish tasks in various ways. it’s not necessarily a bad thing.
task.spawn is a simpler way to use coroutines that don’t provide any way of closing/resuming functions/tasks created with it
local thread
function test()
thread = coroutine.running()
coroutine.yield(thread)
print("Hi, I can control threads fine without a coroutine.resume footgun breaking the task scheduler")
end
task.spawn(test)
task.wait(5)
task.spawn(thread)
What exactly can coroutine.resume do that task.spawn cant?
task.spawn returns a coroutine but i usually prefer just using coroutine.create for this purpose. and i use coroutine.resume whenever and where i want to start it.
but i usually prefer just using coroutine.create for this purpose
But WHY? It breaks the task scheduler. What does direct coroutine.resume get you that task.spawn doesn’t preferably with a code example, because otherwise your just making your thread get lost to the task scheduler for no reason.
My point is, you can just use coroutine.create with task.spawn to get the fine grained scheduling behavior of coroutines if you want to create and not instantly run - and the task scheduler doesn’t blow up if you do so.
function test()
print("Hi, I can control threads fine")
end
local myThread = coroutine.create(test)
print("Lets run my thread soon!")
task.wait(5)
task.spawn(myThread)
So why is coroutine.resume NOT deprecated if it has no additional use cases and breaks the task scheduler.
Either there is another use case that I’m not seeing - or it legitimately should be marked as deprecated in RBXLua.
Multiple ways of doing different things aint bad, but if one of them leads to hard to debug glitches and the other has no evident downside, the path becomes obvious.
Also your point on task.spawn and coroutine.resume having different purposes has already been answered by EmptySet, it’s just not a real thing, I don’t know how you all keep hallucinating that coroutine.resume has some magical extra property and advanced usage.
you can establish a two way communciation channel with coroutine.yield and coroutine.resume, it’s actually useful. you can’t replicate this with task.spawn
i already said, you can’t establish a two-way communication without coroutines.
an example here:
local co = coroutine.create(function()
local a = coroutine.yield("first number?")
local b = coroutine.yield("second number?")
return a + b
end)
local _, prompt1 = coroutine.resume(co)
local _, prompt2 = coroutine.resume(co, 10)
local _, sum = coroutine.resume(co, 20)
print(sum) -- 30
btw task doesn’t even exist in regular luau so there’s no point in deprecating ts
this has to be one of the craziest feature requests i’ve ever seen
Alright, it breaks that radioactive code, that’s a fair counterpoint. I still wish coroutine.resume was labelled so that the schedule breaking behavior is not so easy to miss.
The fact that task doesn’t exist doesn’t change anything, not sure why you felt the need to add that at the end.
Honestly on a design standpoint, at this point I would prefer for task.spawn to be able to extablish two way communication. I can see how it could be useful but I would still never use it cause if somebody calls the yielding function from module scope, you’ll end up with the main script stopping execution and any nested module literally being garbage collected as they executed. It’s a disaster that leaves no proper debugging traces.
I wouldn’t recommend anyone use coroutine.resume regardless. If you want two way communication you could still simulate it with your own library, actually you SHOULD. Especially if you work in a team environment, somebody calling your coroutine.resume containing code from module scope is a disaster waiting to happen.
Problem with gc causing modules to stop executing is that it is non-deterministic, so your game will silently break in unexpected ways in production. You could cause irreparable data corruption.
just don’t yield at the module/top level scope, always use it in functions because if you use it within the module scope you just get undefined behaviour.