Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra tips for running IO #885

Merged
merged 2 commits into from
Jun 13, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/docs/arrow-docs/docs/docs/effects/io/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Running in this context means evaluating the content of an `IO` object, and prop

Note that `IO` objects can be run multiple times, and depending on how they are constructed they will evaluate its content again every time they're run.

The general good practice is to have a single unsafe run call per program, at the entry point. In backend applications or command line tools this can be at the main. For Android apps, specially those before Android 9.0, this could happen per Activity.

### attempt

Executes and defers the result into a new `IO` that has captured any exceptions inside `Either<Throwable, A>`.
Expand All @@ -40,6 +42,8 @@ All exceptions that would happen on the function parameter are automatically cap

It runs the current `IO` asynchronously, calling the callback parameter on completion and returning its result.

The operation will not yield a result immediately; ultimately to start running the suspended computation you have to evaluate that new instance using an unsafe operator like `unsafeRunAsync` or `unsafeRunSync` for `IO`.

```kotlin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we are not using ank on these snippets?

Could we perhaps add an additional snippet to accompany the added docs?

val io = IO<Int> { throw RuntimeException("Boom!") }
  .runAsync { result ->
    result.fold({ IO { println("Error") } }, { IO { println(it.toString()) } })
  }

The operation will ...

Copy link
Member Author

@pakoito pakoito Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async operations fail to execute on Ank. That snippet is right below this paragraph, if you expand the file.

IO<Int> { throw RuntimeException("Boom!") }
.runAsync { result ->
Expand Down