Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making coru Object Oriented #6

Open
hattesen opened this issue Nov 2, 2023 · 0 comments
Open

Making coru Object Oriented #6

hattesen opened this issue Nov 2, 2023 · 0 comments

Comments

@hattesen
Copy link

hattesen commented 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:

  • 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

@hattesen hattesen changed the title Making coru object oriented Making coru Object Oriented Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant