Skip to content

Instantly share code, notes, and snippets.

@satanworker
Created May 29, 2023 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satanworker/6b45268343a1411890df2a8c2f8faa1a to your computer and use it in GitHub Desktop.
Save satanworker/6b45268343a1411890df2a8c2f8faa1a to your computer and use it in GitHub Desktop.
`flatMap` на вход приходит (String) и на выход `Effect(result)`
func testAsyncEffect() -> Effect<Int, MainError> {
Effect<String, MainError>.future { callback in
DispatchQueue.global().async {
sleep(5)
callback(.success("All good"))
}
}
.flatMap { value -> Effect<Int, MainError> in
Effect.result {
.success(2)
}
}
.eraseToEffect()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment