crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.26k stars 1.61k forks source link

Add `Fiber.suspend` #14560

Closed ysbaddaden closed 2 months ago

ysbaddaden commented 2 months ago

Replaces the private Crystal::Scheduler.reschedule method that suspends the execution of the current fiber (that must be manually re-enqueued to be resumed) with a public method: Fiber.suspend.

[!NOTE] It could be Fiber.reschedule. I'm not sure which term is more explicit and closer to the intent?

Related to the other PRs that abstract Crystal::Scheduler away.

Relates to: https://github.com/crystal-lang/crystal/issues/5204

straight-shoota commented 2 months ago

I think suspend fits better than reschedule. The latter works in the context of Scheduler, but we're not rescheduling the fiber, we're suspending it.