Convenience asynchronous completion handlers

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: GitHub - jjrscott/AsyncCompletionHandler: Generate convenience async completion handlers.

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 :man_shrugging:t2:

Terms of Service

Privacy Policy

Cookie Policy