Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Comparative Asynchronous Programming

Ash Furrow
February 24, 2017

Comparative Asynchronous Programming

Presented at Playgrounds Conf: http://www.playgroundscon.com/

Ash Furrow

February 24, 2017
Tweet

More Decks by Ash Furrow

Other Decks in Programming

Transcript

  1. Agenda 1. Asynchronous programming is hard. 2. Swift already supports

    a few async methodologies. 3. Swift supports some other paradigms. 4. But lacks support for others.
  2. getCredentialsFromUser() { credentials, error in if credentials { logIn(with: credentials)

    { login, error in if login { // Handle login success } else { // Handle error } } } else { // Handle error } }
  3. getCredentialsFromUser() .flatMap { credentials in return login(with: credentials) } .onSuccess

    { login in // Handle login success } .onFailure { error in // Handle login error }
  4. getCredentialsFromUser() .flatMap { credentials in return login(with: credentials) } .on(next:

    { login in // Handle login success }, error: { error in // Handle login error })
  5. async func logIn() -> Login { let credentials = await

    getCredentialsFromUser() return await logIn(with: credentials) }
  6. func fibGenerator*() -> Int { var i = 0, j

    = 1 repeat { let next = i + j yield next (i, j) = (j, next) } while true } fibGenerator() // returns 1 fibGenerator() // returns 2 fibGenerator() // returns 3 fibGenerator() // returns 5
  7. Wrap Up 1. There’s no “right way” to do async

    programming. 2. Asynchronous abstractions built into Swift aren’t great. 3. There are some cool things you can do in Swift. 4. There are other cool things that you can’t do in Swift.