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

Refactor entry point. #464

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/jaguar.toit
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,22 @@ container-done / monitor.Semaphore ::= monitor.Semaphore
registry_ / ContainerRegistry ::= ContainerRegistry

main arguments:
device := Device.parse arguments
endpoints := [
EndpointHttp logger,
]
uart := device.config.get "endpointUart"
if uart: endpoints.add (EndpointUart --config=uart --logger=logger)
main device endpoints

main device/Device endpoints/List:
try:
// We try to start all installed containers, but we catch any
// exceptions that might occur from that to avoid blocking
// the Jaguar functionality in case something is off.
catch --trace: run-installed-containers
// We are now ready to start Jaguar.
serve arguments
serve device endpoints
finally: | is-exception exception |
// We shouldn't be able to get here without an exception having
// been thrown, but we play it defensively and force an exception
Expand Down Expand Up @@ -91,14 +100,7 @@ run-installed-containers -> none:
semaphore.up
blockers.size.repeat: semaphore.down

serve arguments:
device := Device.parse arguments
endpoints := [
EndpointHttp logger,
]
if device.config.contains "endpointUart":
endpoints.add (EndpointUart --config=device.config["endpointUart"] --logger=logger)

serve device endpoints:
lambdas := []
for i := 0; i < endpoints.size; i++:
endpoint/Endpoint := endpoints[i]
Expand Down