From e8f35637fd0212760ac241eed18cf8b685d90ba8 Mon Sep 17 00:00:00 2001 From: Kasper Lund Date: Tue, 6 Feb 2024 08:35:40 +0100 Subject: [PATCH] Make ethernet and cellular clients more robust against cancelation (#2074) --- ...t-supabase__examples__auth_email.toit.gold | 36 ------------------- ...t-supabase__examples__auth_oauth.toit.gold | 30 ---------------- .../toit-supabase__examples__rest.toit.gold | 30 ---------------- ...toit-supabase__examples__storage.toit.gold | 30 ---------------- ...upabase__examples__utils__client.toit.gold | 30 ---------------- ...__examples__utils__local_storage.toit.gold | 30 ---------------- .../gold/toit-supabase__src__auth.toit.gold | 18 ---------- .../gold/toit-supabase__src__filter.toit.gold | 18 ---------- .../toit-supabase__src__supabase.toit.gold | 18 ---------- ..._supabase__supabase_filters_test.toit.gold | 18 ---------- ..._supabase__supabase_local_server.toit.gold | 18 ---------- ...__tests__supabase__supabase_test.toit.gold | 18 ---------- lib/net/cellular.toit | 20 ++++++++++- lib/net/ethernet.toit | 20 ++++++++++- 14 files changed, 38 insertions(+), 296 deletions(-) delete mode 100644 external/gold/toit-supabase__examples__auth_email.toit.gold delete mode 100644 external/gold/toit-supabase__examples__auth_oauth.toit.gold delete mode 100644 external/gold/toit-supabase__examples__rest.toit.gold delete mode 100644 external/gold/toit-supabase__examples__storage.toit.gold delete mode 100644 external/gold/toit-supabase__examples__utils__client.toit.gold delete mode 100644 external/gold/toit-supabase__examples__utils__local_storage.toit.gold delete mode 100644 external/gold/toit-supabase__src__auth.toit.gold delete mode 100644 external/gold/toit-supabase__src__filter.toit.gold delete mode 100644 external/gold/toit-supabase__src__supabase.toit.gold delete mode 100644 external/gold/toit-supabase__tests__supabase__supabase_filters_test.toit.gold delete mode 100644 external/gold/toit-supabase__tests__supabase__supabase_local_server.toit.gold delete mode 100644 external/gold/toit-supabase__tests__supabase__supabase_test.toit.gold diff --git a/external/gold/toit-supabase__examples__auth_email.toit.gold b/external/gold/toit-supabase__examples__auth_email.toit.gold deleted file mode 100644 index f88c29902..000000000 --- a/external/gold/toit-supabase__examples__auth_email.toit.gold +++ /dev/null @@ -1,36 +0,0 @@ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:8: warning: Deprecated 'platform' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:20: warning: Deprecated 'PLATFORM-WINDOWS' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/auth_email.toit:9:20: warning: Deprecated 'program-name' - print "Usage: $program_name signup " - ^~~~~~~~~~~~ -toit-supabase/examples/auth_email.toit:18:20: warning: Deprecated 'program-name' - print "Usage: $program_name login " - ^~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:19: warning: Deprecated 'platform' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:31: warning: Deprecated 'PLATFORM-WINDOWS' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__examples__auth_oauth.toit.gold b/external/gold/toit-supabase__examples__auth_oauth.toit.gold deleted file mode 100644 index 6dc91bde3..000000000 --- a/external/gold/toit-supabase__examples__auth_oauth.toit.gold +++ /dev/null @@ -1,30 +0,0 @@ -toit-supabase/examples/utils/local_storage.toit:72:8: warning: Deprecated 'platform' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:20: warning: Deprecated 'PLATFORM-WINDOWS' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:19: warning: Deprecated 'platform' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:31: warning: Deprecated 'PLATFORM-WINDOWS' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__examples__rest.toit.gold b/external/gold/toit-supabase__examples__rest.toit.gold deleted file mode 100644 index 6dc91bde3..000000000 --- a/external/gold/toit-supabase__examples__rest.toit.gold +++ /dev/null @@ -1,30 +0,0 @@ -toit-supabase/examples/utils/local_storage.toit:72:8: warning: Deprecated 'platform' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:20: warning: Deprecated 'PLATFORM-WINDOWS' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:19: warning: Deprecated 'platform' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:31: warning: Deprecated 'PLATFORM-WINDOWS' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__examples__storage.toit.gold b/external/gold/toit-supabase__examples__storage.toit.gold deleted file mode 100644 index 6dc91bde3..000000000 --- a/external/gold/toit-supabase__examples__storage.toit.gold +++ /dev/null @@ -1,30 +0,0 @@ -toit-supabase/examples/utils/local_storage.toit:72:8: warning: Deprecated 'platform' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:20: warning: Deprecated 'PLATFORM-WINDOWS' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:19: warning: Deprecated 'platform' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:31: warning: Deprecated 'PLATFORM-WINDOWS' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__examples__utils__client.toit.gold b/external/gold/toit-supabase__examples__utils__client.toit.gold deleted file mode 100644 index cf9c27daa..000000000 --- a/external/gold/toit-supabase__examples__utils__client.toit.gold +++ /dev/null @@ -1,30 +0,0 @@ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:8: warning: Deprecated 'platform' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:20: warning: Deprecated 'PLATFORM-WINDOWS' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:19: warning: Deprecated 'platform' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:31: warning: Deprecated 'PLATFORM-WINDOWS' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__examples__utils__local_storage.toit.gold b/external/gold/toit-supabase__examples__utils__local_storage.toit.gold deleted file mode 100644 index cf9c27daa..000000000 --- a/external/gold/toit-supabase__examples__utils__local_storage.toit.gold +++ /dev/null @@ -1,30 +0,0 @@ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:8: warning: Deprecated 'platform' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:72:20: warning: Deprecated 'PLATFORM-WINDOWS' - if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:19: warning: Deprecated 'platform' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/examples/utils/local_storage.toit:24:31: warning: Deprecated 'PLATFORM-WINDOWS' - if not home and platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__src__auth.toit.gold b/external/gold/toit-supabase__src__auth.toit.gold deleted file mode 100644 index 87854cebc..000000000 --- a/external/gold/toit-supabase__src__auth.toit.gold +++ /dev/null @@ -1,18 +0,0 @@ -toit-supabase/src/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -toit-supabase/src/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -toit-supabase/src/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -toit-supabase/src/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -toit-supabase/src/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/src/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__src__filter.toit.gold b/external/gold/toit-supabase__src__filter.toit.gold deleted file mode 100644 index 87854cebc..000000000 --- a/external/gold/toit-supabase__src__filter.toit.gold +++ /dev/null @@ -1,18 +0,0 @@ -toit-supabase/src/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -toit-supabase/src/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -toit-supabase/src/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -toit-supabase/src/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -toit-supabase/src/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/src/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__src__supabase.toit.gold b/external/gold/toit-supabase__src__supabase.toit.gold deleted file mode 100644 index 87854cebc..000000000 --- a/external/gold/toit-supabase__src__supabase.toit.gold +++ /dev/null @@ -1,18 +0,0 @@ -toit-supabase/src/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -toit-supabase/src/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -toit-supabase/src/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -toit-supabase/src/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -toit-supabase/src/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -toit-supabase/src/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__tests__supabase__supabase_filters_test.toit.gold b/external/gold/toit-supabase__tests__supabase__supabase_filters_test.toit.gold deleted file mode 100644 index 1bd4ce228..000000000 --- a/external/gold/toit-supabase__tests__supabase__supabase_filters_test.toit.gold +++ /dev/null @@ -1,18 +0,0 @@ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__tests__supabase__supabase_local_server.toit.gold b/external/gold/toit-supabase__tests__supabase__supabase_local_server.toit.gold deleted file mode 100644 index 1bd4ce228..000000000 --- a/external/gold/toit-supabase__tests__supabase__supabase_local_server.toit.gold +++ /dev/null @@ -1,18 +0,0 @@ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/external/gold/toit-supabase__tests__supabase__supabase_test.toit.gold b/external/gold/toit-supabase__tests__supabase__supabase_test.toit.gold deleted file mode 100644 index 1bd4ce228..000000000 --- a/external/gold/toit-supabase__tests__supabase__supabase_test.toit.gold +++ /dev/null @@ -1,18 +0,0 @@ -/auth.toit:112:14: warning: Deprecated 'platform' - if platform == PLATFORM_LINUX: - ^~~~~~~~ -/auth.toit:112:26: warning: Deprecated 'PLATFORM-LINUX' - if platform == PLATFORM_LINUX: - ^~~~~~~~~~~~~~ -/auth.toit:115:19: warning: Deprecated 'platform' - else if platform == PLATFORM_MACOS: - ^~~~~~~~ -/auth.toit:115:31: warning: Deprecated 'PLATFORM-MACOS' - else if platform == PLATFORM_MACOS: - ^~~~~~~~~~~~~~ -/auth.toit:118:19: warning: Deprecated 'platform' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~ -/auth.toit:118:31: warning: Deprecated 'PLATFORM-WINDOWS' - else if platform == PLATFORM_WINDOWS: - ^~~~~~~~~~~~~~~~ diff --git a/lib/net/cellular.toit b/lib/net/cellular.toit index 8c25427be..f6482e79b 100644 --- a/lib/net/cellular.toit +++ b/lib/net/cellular.toit @@ -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 diff --git a/lib/net/ethernet.toit b/lib/net/ethernet.toit index d75b549d0..49c9ac8f9 100644 --- a/lib/net/ethernet.toit +++ b/lib/net/ethernet.toit @@ -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