Stylianos Gakis
11/08/2025, 5:21 PMfunc foo() async throws -> Token?. Not sure if I can call a Swift async function from Kotlin, we typically only do it the other way around. Is there any possible way you can imagine how I can reach that from inside my Apollo interceptor, or will I have to do something different altogether for this?ephemient
11/08/2025, 6:03 PMasync can be exposed to Objective-C as a callback-based completionHandler:, which should be natural to use with suspendCoroutine in Kotlin. not sure what you'd do from a non-suspend context thoughStylianos Gakis
11/11/2025, 9:43 AMinterface AccessTokenFetcher {
fun fetch(): String
}
which I expect iOS to provide an implementation for, and the ApolloInterceptor uses in order to get the header during the interception.
Then on iOS I added this (where foo() is the aforementioned async function)
class KeychainAccessTokenFetcher : AccessTokenFetcher {
func fetch() -> String? {
final class TokenBox: @unchecked Sendable {
var token: String?
}
let semaphore = DispatchSemaphore(value: 0)
let box = TokenBox()
Task {
do {
box.token = try await foo().accessToken
} catch {
box.token = nil
}
semaphore.signal()
}
semaphore.wait()
return box.token
}
}
Which does seem to work, albeit looks nothing like what I'd do in Kotlin normally.
I will have to figure out a better way I think, but at least I am unblocking myself for now.dorche
11/12/2025, 7:51 PMfetch function in the interface is not a suspend function?Stylianos Gakis
11/12/2025, 8:48 PMdorche
11/12/2025, 11:06 PMStylianos Gakis
11/13/2025, 7:09 AMdorche
11/13/2025, 8:47 AMStylianos Gakis
11/13/2025, 1:00 PMdorche
11/13/2025, 2:57 PMpublic interface TokenFetcher {
public val token: String
public suspend fun fetch(): String
public fun setToken(token: String)
}
__attribute__((swift_name("TokenFetcher")))
@protocol SharedTokenFetcher
@required
/**
* @note This method converts instances of CancellationException to errors.
* Other uncaught Kotlin exceptions are fatal.
*/
- (void)fetchWithCompletionHandler:(void (^)(NSString * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("fetch(completionHandler:)")));
- (void)setTokenToken:(NSString *)token __attribute__((swift_name("setToken(token:)")));
@property (readonly) NSString *token __attribute__((swift_name("token")));
@endStylianos Gakis
11/13/2025, 10:30 PMStylianos Gakis
11/14/2025, 8:38 PM