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
onSuccessand returned fromresult().Declaration
Swift
associatedtype Success : Sendable -
The typed failure delivered to
onFailureand thrown fromresult(). Must beNSError(typicallyMoEngageRequestFailure).Declaration
Swift
associatedtype Failure : NSError
-
onSuccess(_:Extension method) Register a typed success handler. Single-slot: a second call replaces the previous handler. Returns
selffor 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
selffor chaining.Declaration
Swift
@discardableResult func onFailure(_ handler: @MainActor @escaping (Failure) -> Void) -> Self -
result()Extension method, asynchronousasync/awaitthe task’s outcome. Returns the typedSuccess; throws the typedFailure, or.unknownErrorif cancelled.Important
result()registers its ownonSuccess/onFailure. Because handler slots are single-writer, attachingonSuccess { ... }AND awaitingresult()on the same task drops the closure — use one surface per task.Declaration
Swift
func result() async throws -> Success