jjrscott

Convenience asynchronous completion handlers

Swift Forums:

This pitch proposes that the standard library be amended to contain convenience functions for the most common types of asynchronous completion handlers.

withUnsafeContinuation et al are very flexible and useful, but most use cases are in a very confined area:

func getFoo(..., completion: @escaping (Foo,...)->Void)
func getFoo(..., completion: @escaping (Result<Foo,Error>)->Void)
func getFoo(..., completion: @escaping (Foo?,Error?)->Void) // Foo xor Error
func getFoo(..., completion: @escaping (Foo?,Error?)->Void) // Foo and Error

I have attached a draft of the functions here: https://github.com/jjrscott/AsyncCompletionHandler.

A counter argument is that completion handlers are on the way out so why put transitory functions in the Standard Library. I honestly don’t know if they’ll stay or go.