api-swift / Sources / IrdAPI / Flows / ActionsFlow.swift
113 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import Foundation

extension RegistrationsAPI {
    /// Polls a registry action until it is `succeeded`, `failed` or `cancelled` and
    /// returns it; failures are results the caller reads, not errors.
    public func waitForAction(id: String, options: PollOptions = .actions) async throws -> RegistrationAction {
        try await pollUntil(options, clock: client.configuration.clock,
                            step: { try await getAction(id: id).action },
                            done: { [.succeeded, .failed, .cancelled].contains($0.state) })
    }
}

extension VPSAPI {
    /// Polls a VPS action until it is `succeeded`, `failed` or `cancelled` and returns it.
    public func waitForAction(id: String, options: PollOptions = .actions) async throws -> VPSAction {
        try await pollUntil(options, clock: client.configuration.clock,
                            step: { try await getAction(id: id).action },
                            done: { [.succeeded, .failed, .cancelled].contains($0.state) })
    }
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/api-swift.git