Skip to content

Commit

Permalink
Refactor entry point. (#464)
Browse files Browse the repository at this point in the history
Parse the arguments only in main, and pass on the parsed arguments.

---------

Co-authored-by: Kasper Lund <kasper@toit.io>
  • Loading branch information
floitsch and kasperl committed Jan 15, 2024
1 parent ab566a8 commit 84e1fac
Showing 1 changed file with 11 additions and 9 deletions.
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

0 comments on commit 84e1fac

Please sign in to comment.