field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

TeraRuntimeResourceCreation.swift (1505B)


      1 enum TeraRuntimeResourceCreation {
      2   static func startup(
      3     configuration: TeraRuntimeLaunchConfiguration,
      4     factory: @escaping TeraRuntimeBackendFactory,
      5     identity: TeraRuntimeOperationIdentity,
      6     deadlines: TeraRuntimeDeadlinePolicy
      7   ) -> TeraRuntimeResourceTask<TeraRuntimeBackendStart> {
      8     TeraRuntimeResourceTask(
      9       deadlineNanoseconds: deadlines.startupNanoseconds,
     10       cleanupDeadlineNanoseconds: deadlines.shutdownNanoseconds,
     11       operation: {
     12         do {
     13           return try await .success(factory(configuration))
     14         } catch {
     15           return .failure(TeraRuntimeClient.failure(from: error, operation: identity.rawValue))
     16         }
     17       },
     18       cleanup: { started in
     19         _ = try await started.backend.shutdown()
     20       }
     21     )
     22   }
     23 
     24   static func subscription(
     25     backend: any TeraRuntimeBackend,
     26     bufferCapacity: Int,
     27     identity: TeraRuntimeOperationIdentity,
     28     deadline: UInt64,
     29     receive: @escaping @Sendable (TeraRuntimeChange) async -> Void
     30   ) -> TeraRuntimeResourceTask<any TeraRuntimeSubscriptionToken> {
     31     TeraRuntimeResourceTask(
     32       deadlineNanoseconds: deadline,
     33       cleanupDeadlineNanoseconds: deadline,
     34       operation: {
     35         do {
     36           return try await .success(backend.subscribe(bufferCapacity: bufferCapacity, receive: receive))
     37         } catch {
     38           return .failure(TeraRuntimeClient.failure(from: error, operation: identity.rawValue))
     39         }
     40       },
     41       cleanup: { token in await token.cancel() }
     42     )
     43   }
     44 }