Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Improve Arrow Fx Coroutines docs for release #248

Merged
merged 32 commits into from
Aug 15, 2020
Merged

Conversation

nomisRev
Copy link
Member

@nomisRev nomisRev commented Aug 11, 2020

Another iteration over the docs.
This PR goes together with arrow-kt/arrow-site#64 which updates the sidebar of the Arrow Fx website to promote Arrow Fx Coroutines for the next version.

Quickstart section

Updated the second page from the Arrow Fx website Quickstart to Arrow Fx Coroutines, this leaves the 3rd page which talks about tagless effects.

This could become a page that in more detail explains the integrations and cancellation in the standard library, etc.
A fourth page could be added to the quickstart which covers the IO vs suspend section currently in the README.MD of Arrow Fx Coroutines. It could also include a small migration guide from IO to suspend as today was asked on Slack

Data type section (non-blockers for PR)

  • CircuitBreaker only has API documentation. It was inspired by Monix's CircuitBreaker which in turn was inspired by Akka's CircuitBreaker. Monix's seems to overlap with Akka's docs, so perhaps with the correct credits we can do the same. link.

  • API docs are a very low profile and have little to no styling. I'm not sure how or if we need to improve our API docs, or if we should promote certain functions in a different manner. parMapN, parTupledN, raceN.

* Reason being, we cannot [release] what we did not `acquire` first. Same reason we cannot call [use].
* If it is successful we pass the result to stage 2 [use].
*
* 2. Resource consumption is like any other `suspend` effect. The key difference here is that it's wired in such a way that
Copy link
Member

Choose a reason for hiding this comment

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

Excellent docs and clarifications!

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we repeat this in bracket, I am unsure how we can improve the documentation of these top-level functions.

API docs are a very low profile and have little to no styling. I'm not sure how or if we need to improve our API docs, or if we should promote certain functions in a different manner. parMapN, parTupledN, raceN.

* }
*
* suspend fun main(): Unit {
* val fiber = ForkConnected {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not clear about the name ForkConnected. Could you elaborate a bit about why the Connected part?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added docs for ForkConnected with an example after this comment :D link

Reasoning for new ForkConnected and ForkScoped functions

In Arrow Fx IO we only had fork which launches a Fiber without any cancellation connection control. Meaning you always leak unless you launch a Fiber inside Resource or bracketCase as the acquire step.
This makes fork quite complicated and easily results in cancellation bugs etc. Those semantics of IO's fork is now an combinator called `ForkAndForget.

Some more info here. We should probably also document these, but this comes back to trying to figure out a way to add higher-level documentation to top-level functions besides function docs. Or do you think we should include all of that there?

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

thanks @nomisRev ! 🙏

@nomisRev
Copy link
Member Author

@raulraja Thanks for the review! Did I address all your comments? Do you have any feedback on my two questions (checkboxes)?

@nomisRev nomisRev mentioned this pull request Aug 12, 2020
isDaemon = true
}
}.asCoroutineContext()

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Awesome @nomisRev !! I think KLint is complaining about this extra line!

Copy link
Contributor

@PhBastiani PhBastiani left a comment

Choose a reason for hiding this comment

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

Great !

WARNING : these commits impact not only the doc but also the code and the tests

arrow-fx-coroutines/README.MD Outdated Show resolved Hide resolved
@@ -14,6 +14,32 @@ import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
* The winner of the race cancels the other participants,
* cancelling the operation cancels all participants.
Copy link
Contributor

Choose a reason for hiding this comment

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

What if a participant is uncancellable ?

@@ -209,6 +212,61 @@ sealed class Resource<out A> {
fun <A> defer(f: suspend () -> Resource<A>): Resource<A> =
Resource.Defer(f)

/**
* Creates a single threaded [CoroutineContext] as a [Resource].
Copy link
Contributor

@PhBastiani PhBastiani Aug 13, 2020

Choose a reason for hiding this comment

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

Please add detail (release part) : e.g. specify that the submitted tasks will be executed before terminating

Resource(f) { s -> s.shutdown() }.map(ExecutorService::asCoroutineContext)

/**
* Creates a single threaded [CoroutineContext] as a [Resource].
Copy link
Contributor

@PhBastiani PhBastiani Aug 13, 2020

Choose a reason for hiding this comment

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

Please add detail (release part) : e.g. specify that the submitted tasks will be executed before terminating

@@ -6,6 +6,28 @@ import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn
/**
* Checks for cancellation,
* when cancellation occurs this coroutine will suspend indefinitely and never continue.
Copy link
Contributor

Choose a reason for hiding this comment

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

The example is clear ... but, the textual explanation does not seem sufficient to understand the purpose of cancelBoundary

Copy link
Member Author

Choose a reason for hiding this comment

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

What about the following instead? I found this terribly hard to document.

"Inserts a cancellable boundary — it checks for the cancellation status of the suspend-loop and does not allow the continuation to keep executing in the case cancellation happened."

Copy link
Contributor

@PhBastiani PhBastiani Aug 13, 2020

Choose a reason for hiding this comment

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

Maybe:

"In a cancelable environment, we need to add mechanisms to react when a cancellation is triggered : a cancel boundary inserts checking point in suspendable methods. At runtime, a cancel boundary checks for the cancellation status; and, it does not allow the continuation of task to keep executing in the case a cancellation was triggered.
Useful, for example, to cancel the continuation of a loop, as shown in this code snippet:"

Or, something like that

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you @PhBastiani! That is a much better improvement over what I did 😅

@rachelcarmena
Copy link
Member

About:

* API docs are a very low profile and have little to no styling. I'm not sure how or if we need to improve our API docs, or if we should promote certain functions in a different manner. 

Let's try the new Dokka which introduces a modern HTML format!!

@nomisRev
Copy link
Member Author

@PhBastiani Thanks for the amazing review and taking the time to go through the PR! 👍
Please let me know if you think I address all your comments.

@rachelcarmena rachelcarmena merged commit ad96d2e into master Aug 15, 2020
@rachelcarmena rachelcarmena deleted the sv-docs-draft branch August 15, 2020 15:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants