Created
May 29, 2023 19:28
-
-
Save satanworker/92b0664631b4914372fbd11d039a923e to your computer and use it in GitHub Desktop.
`.eraseToEffect` - когда нужно схлопнуть несколько операторов в один эффект, чтобы компилятор не отъехал
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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