[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 12/32: AsyncSemaphore to serialize Getbalances
From: |
gnunet |
Subject: |
[taler-taler-ios] 12/32: AsyncSemaphore to serialize Getbalances |
Date: |
Mon, 16 Oct 2023 00:03:10 +0200 |
This is an automated email from the git hooks/post-receive script.
marc-stibane pushed a commit to branch master
in repository taler-ios.
commit 696dfc84922362363a75859aeb6b3bf3c8366dc3
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Oct 13 10:05:29 2023 +0200
AsyncSemaphore to serialize Getbalances
---
TalerWallet1/Model/Model+Balances.swift | 21 ++++++++++++++-------
TalerWallet1/Model/WalletModel.swift | 3 ++-
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/TalerWallet1/Model/Model+Balances.swift
b/TalerWallet1/Model/Model+Balances.swift
index 3c5c585..c5fa095 100644
--- a/TalerWallet1/Model/Model+Balances.swift
+++ b/TalerWallet1/Model/Model+Balances.swift
@@ -45,13 +45,20 @@ extension WalletModel {
/// fetch Balances from Wallet-Core. No networking involved
@MainActor func balancesM(_ stack: CallStack)
async -> [Balance] { // M for MainActor
- do {
- let request = Balances()
- let response = try await sendRequest(request, ASYNCDELAY)
- return response.balances // trigger view update in
BalancesListView
- } catch {
- logger.error("balancesM failed: \(error)")
- return []
+ await semaphore.wait()
+ defer { semaphore.signal() }
+ if cachedBalances == nil {
+ do {
+ let request = Balances()
+ let response = try await sendRequest(request, ASYNCDELAY)
+ cachedBalances = response.balances
+ } catch {
+ logger.error("balancesM failed: \(error)")
+ // TODO: show error
+ }
+ } else {
+ logger.trace("returning cached Balances")
}
+ return cachedBalances ?? []
}
}
diff --git a/TalerWallet1/Model/WalletModel.swift
b/TalerWallet1/Model/WalletModel.swift
index 508fbf9..6a24d8e 100644
--- a/TalerWallet1/Model/WalletModel.swift
+++ b/TalerWallet1/Model/WalletModel.swift
@@ -9,13 +9,14 @@ import os.log
fileprivate let DATABASE = "talerwalletdb-v30"
fileprivate let ASYNCDELAY: UInt = 0 //set e.g to 6 or 9 seconds for
debugging
-
// MARK: -
/// The "virtual" base class for all models
class WalletModel: ObservableObject {
public static let shared = WalletModel()
static func className() -> String {"\(self)"}
let logger = Logger (subsystem: "net.taler.gnu", category: "WalletModel")
+ let semaphore = AsyncSemaphore(value: 1)
+ var cachedBalances: [Balance]? = nil
func sendRequest<T: WalletBackendFormattedRequest> (_ request: T, _ delay:
UInt = 0)
async throws -> T.Response { // T for any Thread
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] 15/32: TwoRowButtons, (continued)
- [taler-taler-ios] 15/32: TwoRowButtons, gnunet, 2023/10/15
- [taler-taler-ios] 05/32: No spellout, gnunet, 2023/10/15
- [taler-taler-ios] 09/32: TabBar for Taler Wallet - GNU Taler stays on SideView, gnunet, 2023/10/15
- [taler-taler-ios] 16/32: Source of Truth for balances, gnunet, 2023/10/15
- [taler-taler-ios] 30/32: font, gnunet, 2023/10/15
- [taler-taler-ios] 27/32: SingleAxisGeometryReader, gnunet, 2023/10/15
- [taler-taler-ios] 06/32: More CallStack for Debugging, gnunet, 2023/10/15
- [taler-taler-ios] 07/32: AsyncSemaphore, gnunet, 2023/10/15
- [taler-taler-ios] 23/32: fix for broken scalable font (not finished), gnunet, 2023/10/15
- [taler-taler-ios] 11/32: bankAccessApiBaseUrl -> corebankApiBaseUrl, gnunet, 2023/10/15
- [taler-taler-ios] 12/32: AsyncSemaphore to serialize Getbalances,
gnunet <=
- [taler-taler-ios] 31/32: comment, gnunet, 2023/10/15
- [taler-taler-ios] 25/32: Bargraph after Currency, gnunet, 2023/10/15
- [taler-taler-ios] 32/32: Bump version to 0.9.3 (20), gnunet, 2023/10/15
- [taler-taler-ios] 21/32: cleanup, gnunet, 2023/10/15
- [taler-taler-ios] 26/32: cleanup, gnunet, 2023/10/15
- [taler-taler-ios] 22/32: badge, gnunet, 2023/10/15
- [taler-taler-ios] 28/32: Button Layout, gnunet, 2023/10/15
- [taler-taler-ios] 20/32: Preparation for Exchange deposit only with positive balance, gnunet, 2023/10/15
- [taler-taler-ios] 29/32: BarGraph also for Exchanges, gnunet, 2023/10/15
- [taler-taler-ios] 24/32: Balance button, gnunet, 2023/10/15