-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move looping into a service, rather than the kernel.
- Loading branch information
Showing
2 changed files
with
22 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
"""A service that contacts other services during the event loop.""" | ||
|
||
from src.lib.core.kernel import Kernel | ||
from src.lib.core.services.service import ServiceMixin | ||
from src.lib.util.registry import RegistryList | ||
|
||
class LoopService(RegistryList, ServiceMixin): | ||
pass | ||
@Kernel.helper | ||
def loop(self): | ||
"""Run the main application loop.""" | ||
# Use the output service as a context manager. | ||
with self.service("output") as display: | ||
# Start the root Component's loop. | ||
root = self.service("root") | ||
while root.alive: | ||
# Allow registered services to react to the loop. | ||
for service in self.service("loop"): | ||
if hasattr(service, "loop"): | ||
service.loop() | ||
|
||
# Continue looping if necessary. | ||
if root.after_loop().get("relaunch"): | ||
# TODO: Reset kernel and services as needed | ||
return True |