You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have you considered making coru Object Oriented where a coroutine becomes a class instance rather than a function?
It would have these benefits:
Coroutine variables/state can be encapsulated in the object as member variables, rather than in global variables.
A coroutine, helper functions and state can be encapsulated in a class making it easy to maintain an overview of the corouting implementation.
Making coroutines polymorphic - implement virtual coroutines (virtual classes) and extending the functionality of an existing coroutine and/or having multiple variants of a coroutine.
The run() method of the coroutine class will be the equivalent of the current coroutine function.
Allows multiple instances of a class to work simultaneously as independent coroutines, which is not possible when using functions and global variables.
A basic Scheduler class could also be provided, and would allow extension and other scheduling primitives such as sleep(millis), yield_until(lambda) etc.
I would be happy to fork and create an implementation myself, but would like to hear your view/feedback on the proposal.
I would hope that it would be possible implement to be minimally invasive to the existing coru implementation allowing the two to coexist side by side.
The equeue project would obviously have to be adapted to accept CoRoutine objects as well.
For inspiration, here is a link to an Object Oriented implementation of ProtoThreads, which provides similar benefits on top of ProtoThreads as this proposal would on top of coru: https://github.com/benhoyt/protothreads-cpp
The text was updated successfully, but these errors were encountered:
hattesen
changed the title
Making coru object oriented
Making coru Object Oriented
Nov 2, 2023
Hi,
Have you considered making
coru
Object Oriented where a coroutine becomes a class instance rather than a function?It would have these benefits:
run()
method of the coroutine class will be the equivalent of the current coroutine function.Scheduler
class could also be provided, and would allow extension and other scheduling primitives such assleep(millis)
,yield_until(lambda)
etc.I would be happy to fork and create an implementation myself, but would like to hear your view/feedback on the proposal.
I would hope that it would be possible implement to be minimally invasive to the existing
coru
implementation allowing the two to coexist side by side.The
equeue
project would obviously have to be adapted to accept CoRoutine objects as well.For inspiration, here is a link to an Object Oriented implementation of ProtoThreads, which provides similar benefits on top of ProtoThreads as this proposal would on top of
coru
: https://github.com/benhoyt/protothreads-cppThe text was updated successfully, but these errors were encountered: