Skip to content

Commit

Permalink
Make ethernet and cellular clients more robust against cancelation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperl authored Feb 6, 2024
1 parent b7eeac4 commit e8f3563
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 296 deletions.
36 changes: 0 additions & 36 deletions external/gold/toit-supabase__examples__auth_email.toit.gold

This file was deleted.

30 changes: 0 additions & 30 deletions external/gold/toit-supabase__examples__auth_oauth.toit.gold

This file was deleted.

30 changes: 0 additions & 30 deletions external/gold/toit-supabase__examples__rest.toit.gold

This file was deleted.

30 changes: 0 additions & 30 deletions external/gold/toit-supabase__examples__storage.toit.gold

This file was deleted.

30 changes: 0 additions & 30 deletions external/gold/toit-supabase__examples__utils__client.toit.gold

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions external/gold/toit-supabase__src__auth.toit.gold

This file was deleted.

18 changes: 0 additions & 18 deletions external/gold/toit-supabase__src__filter.toit.gold

This file was deleted.

18 changes: 0 additions & 18 deletions external/gold/toit-supabase__src__supabase.toit.gold

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 19 additions & 1 deletion lib/net/cellular.toit
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,28 @@ open config/Map? -> net.Client
// generalize this handling for net.open and wifi.open too,
// so we get a shared pattern for dealing with discovering
// such network services at start up.
service-initialized_ = true
service_ = (CellularServiceClient).open
--timeout=(Duration --s=5)
--if-absent=: null
// If opening the client failed due to exceptions or
// cancelation, we will try again next time $open is
// called. If the service was just absent even after
// having waited for it to appear, we will not try
// again unless $reset has been called in between.
service-initialized_ = true
service := service_
if not service: throw "cellular unavailable"
return net.Client service --name=name (service.connect config)

/**
Resets the cellular client.
This allows re-establishing the link to the cellular service
provider at a later time. At that point, the service provider
may have changed, so calling $reset enables reacting to that.
*/
reset -> none:
service := service_
service_ = null
service-initialized_ = false
if service: service.close
20 changes: 19 additions & 1 deletion lib/net/ethernet.toit
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,28 @@ open --name/string?=null -> net.Client:
// generalize this handling for net.open and wifi.open too,
// so we get a shared pattern for dealing with discovering
// such network services at start up.
service-initialized_ = true
service_ = (EthernetServiceClient).open
--timeout=(Duration --s=5)
--if-absent=: null
// If opening the client failed due to exceptions or
// cancelation, we will try again next time $open is
// called. If the service was just absent even after
// having waited for it to appear, we will not try
// again unless $reset has been called in between.
service-initialized_ = true
service := service_
if not service: throw "ethernet unavailable"
return net.Client service --name=name service.connect

/**
Resets the ethernet client.
This allows re-establishing the link to the ethernet service
provider at a later time. At that point, the service provider
may have changed, so calling $reset enables reacting to that.
*/
reset -> none:
service := service_
service_ = null
service-initialized_ = false
if service: service.close

0 comments on commit e8f3563

Please sign in to comment.