diff --git a/MMMAsyncLoadable.podspec b/MMMAsyncLoadable.podspec index bf0df9e..f084622 100644 --- a/MMMAsyncLoadable.podspec +++ b/MMMAsyncLoadable.podspec @@ -6,7 +6,7 @@ Pod::Spec.new do |s| s.name = "MMMAsyncLoadable" - s.version = "0.3.0" + s.version = "0.3.1" s.summary = "Use async/await with MMMLoadable" s.description = s.summary s.homepage = "https://github.com/mediamonks/#{s.name}" @@ -26,4 +26,5 @@ Pod::Spec.new do |s| } s.source_files = [ "Sources/#{s.name}/*.swift" ] s.dependency "MMMLoadable" + s.dependency "MMMCommonCore" end diff --git a/Package.swift b/Package.swift index 7ae6f8c..b6fbfd2 100644 --- a/Package.swift +++ b/Package.swift @@ -18,12 +18,13 @@ let package = Package( ) ], dependencies: [ - .package(name: "MMMLoadable", url: "https://github.com/mediamonks/MMMLoadable", .upToNextMajor(from: "1.7.0")) + .package(name: "MMMLoadable", url: "https://github.com/mediamonks/MMMLoadable", .upToNextMajor(from: "1.7.0")), + .package(name: "MMMCommonCore", url: "https://github.com/mediamonks/MMMCommonCore", .upToNextMajor(from: "1.8.2")) ], targets: [ .target( name: "MMMAsyncLoadable", - dependencies: ["MMMLoadable"] + dependencies: ["MMMLoadable", "MMMCommonCore"] ), .testTarget( name: "MMMAsyncLoadableTests", diff --git a/Sources/MMMAsyncLoadable/AsyncLoadableObserver.swift b/Sources/MMMAsyncLoadable/AsyncLoadableObserver.swift index 5c98f23..f323b1f 100644 --- a/Sources/MMMAsyncLoadable/AsyncLoadableObserver.swift +++ b/Sources/MMMAsyncLoadable/AsyncLoadableObserver.swift @@ -5,6 +5,7 @@ import Foundation import MMMLoadable +import MMMCommonCore /// ``MMMLoadableObserver`` that supports asynchronous closures as it's callback. public final class AsyncLoadableObserver: MMMLoadableObserver { @@ -31,8 +32,12 @@ extension MMMPureLoadableProtocol { /// - Returns: The observer, you usually want to store this outside of the scope, e.g. /// in a private property so it doesn't deallocate right away. public func sink(_ block: @Sendable @escaping (Self) async -> Void) -> AsyncLoadableObserver? { - return AsyncLoadableObserver(loadable: self) { loadable in - await block(loadable as! Self) + return AsyncLoadableObserver(loadable: self) { [weak self] loadable in + guard let self = self else { + assertionFailure("\(MMMTypeName(Self.self)) was lost inside the observer callback?") + return + } + await block(self) } } }