Skip to content

Add async await support in place of completion handlers  #405

Open
@swhitty

Description

@swhitty

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions