What's needed?
Probably all applications will need to start some actors and then wait for them to finish indefinitely. So far this is on the SDK users, but it could be handled by SDK. Also this allows us to find better methods to wait for all actors (or tasks) to finish.
In this case the SDK can also provide sanity checks, like the microgrid_api is properly initialized, before starting all the actors.
Proposed solution
A run() function would be (pseudo-code):
async def run(*actors: Actor) -> None:
# Check the microgrid_api is initialized (it will raise an exception if it isn't)
microgrid_api.get_microgrid_api()
await asyncio.gather(actor.join() for actor in actors)
Then clients will be like:
from frequenz import sdk
from frequenz.sdk import microgrid_api
async def main() -> None:
await microgrid_api.initialize("host", 8080)
actor1 = Actor1()
actor2 = Actor2()
actor3 = Actor3()
await sdk.run(actor1, actor2, actor3)
if __name__ == '__main__':
asyncio.run(main())
Use cases
All apps have to di the join() manually, it bloats the app code (and currently it has an extra issue because of #45).
Alternatives and workarounds
Do the join() manually.
Further improvements to this:
Additional context
No response
What's needed?
Probably all applications will need to start some actors and then wait for them to finish indefinitely. So far this is on the SDK users, but it could be handled by SDK. Also this allows us to find better methods to wait for all actors (or tasks) to finish.
In this case the SDK can also provide sanity checks, like the
microgrid_apiis properly initialized, before starting all the actors.Proposed solution
A
run()function would be (pseudo-code):Then clients will be like:
Use cases
All apps have to di the join() manually, it bloats the app code (and currently it has an extra issue because of #45).
Alternatives and workarounds
Do the join() manually.
Further improvements to this:
Additional context
No response