ios-client-sdk icon indicating copy to clipboard operation
ios-client-sdk copied to clipboard

Add async await support in place of completion handlers

Open swhitty opened this issue 1 year ago • 5 comments

Is your feature request related to a problem? Please describe. The current Swift API is lacking support for async / await. While developers can naively wrap the existing methods with continuations ignoring cancellation, native support for async / await with support for cancellation would be preferred.

Describe the solution you'd like Key APIs that currently include completion handlers also offer an async await extension

public extension LDClient {

  static func start(config: LDConfig, startWaitSeconds: TimeInterval) async throws { .. }

  func setOnline(_ goOnline: Bool) async throws { .. }
  
  func identify(context: LDContext) async throws { .. }
  
}

Describe alternatives you've considered I currently write these extension myself but there are a few issues due to limitations within the public API:

  • start() can call its completion handler multiple times if timeout expires before it becomes online.
  • start(), setOnline() & identifiy() have no API to cancel causing completion handler to receive failure. e.g. URLSessionTask.cancel()

The workarounds for these issues are non trivial.

swhitty avatar Aug 08 '24 00:08 swhitty

Would love to see this!

gqbit avatar Aug 08 '24 00:08 gqbit

Thank you for the feedback! We will take it into consideration.

tanderson-ld avatar Aug 08 '24 15:08 tanderson-ld

Another argument for true async-await support in the LD SDK, right now, activating the Swift 6 compile mode actually breaks the LD SDK.

choulepoka avatar Dec 13 '24 23:12 choulepoka

Any news on this one? Is it on the roadmap?

diogoepsy avatar Jan 29 '25 10:01 diogoepsy

We have tentative plans that will address this and is on our radar.

tanderson-ld avatar Feb 18 '25 15:02 tanderson-ld