MoEngageTaskProtocol

public protocol MoEngageTaskProtocol : AnyObject

Swift-only typed surface for MoEngageBaseTask subclasses. Each subclass binds concrete Success and Failure types; the protocol extension provides typed onSuccess / onFailure and an async throws result(). ObjC consumers use the Any-typed methods on the base class.

  • The typed success payload delivered to onSuccess and returned from result().

    Declaration

    Swift

    associatedtype Success : Sendable
  • The typed failure delivered to onFailure and thrown from result(). Must be NSError (typically MoEngageRequestFailure).

    Declaration

    Swift

    associatedtype Failure : NSError

Available where Self: MoEngageBaseTask

  • onSuccess(_:) Extension method

    Register a typed success handler. Single-slot: a second call replaces the previous handler. Returns self for chaining.

    Declaration

    Swift

    @discardableResult
    func onSuccess(_ handler: @MainActor @escaping (Success) -> Void) -> Self
  • onFailure(_:) Extension method

    Register a typed failure handler. Single-slot: a second call replaces the previous handler. Returns self for chaining.

    Declaration

    Swift

    @discardableResult
    func onFailure(_ handler: @MainActor @escaping (Failure) -> Void) -> Self
  • result() Extension method, asynchronous

    async/await the task’s outcome. Returns the typed Success; throws the typed Failure, or .unknownError if cancelled.

    Important

    result() registers its own onSuccess/onFailure. Because handler slots are single-writer, attaching onSuccess { ... } AND awaiting result() on the same task drops the closure — use one surface per task.

    Declaration

    Swift

    func result() async throws -> Success