Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alexandru
Copy link
Member

@alexandru alexandru commented Sep 24, 2018

This change is related to the changes I also did in Cats-Effect's IO implementation, see:

Task changes to sequence async finalizers, specified via bracket or via Task.cancelable. What this means is that:

  1. internally Task[Unit] is used, in addition to Cancelable values for specifying finalizers
  2. triggering cancellation will now use and chain Task values
  3. we expose additional runAsync variants:
  • runAsyncF that returns a Task[Unit] (aliased CancelToken[Task])
  • runAsyncAndForget, an optimized way to run tasks in cases in which we care not about the result or about cancelling it
  • runAsyncUncancelable, which doesn't return a cancellation token
  1. to make room for these, I also deprecated runAsyncMaybe (which was useless)

I also started a new sub-project of Monix called monix-catnap. This will provide utilities built on Cats-Effect's type classes. And the first traits introduced are:

  • monix.catnap.CancelableF
  • monix.catnap.cancelables.BooleanCancelableF

I don't have time to introduce pure versions of all cancelable types in monix.execution, but that's the plan. I also plan to introduce specialized Ref implementations, like we have in monix.execution.atomic. So catnap intends to provide generic and pure equivalents for what we have in execution.

* cancelling everything when `cancel` gets evaluated.
*/
def collection[F[_]](refs: CancelableF[F]*)(implicit F: Sync[F]): CancelableF[F] =
unsafeApply[F](cancelAll(refs:_*))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this not be @UnsafeBecauseImpure?

Copy link
Member Author

Choose a reason for hiding this comment

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

The actual implementation has no state. Should it be?

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 mean, if it's unsafe, I'd rather wrap it in F[_], but figured there's no point in doing it.

Not sure if I'm right. Maybe I should just wrap it in F[_] to be on the safe side.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought the unsafeApply allocates mutable state, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh, yes, that's a good point. I think my intention was to use wrap, because CancelableF references have to ensure idempotency on their own, no extra protections needed for such a "collection".

Thanks for pointing it out, definitely needs a fix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Glad it helped 👍

@codecov
Copy link

codecov bot commented Sep 24, 2018

Codecov Report

Merging #726 into master will increase coverage by 0.25%.
The diff coverage is 85.07%.

@@            Coverage Diff             @@
##           master     #726      +/-   ##
==========================================
+ Coverage   90.57%   90.82%   +0.25%     
==========================================
  Files         392      398       +6     
  Lines       11007    11133     +126     
  Branches     2050     2077      +27     
==========================================
+ Hits         9970    10112     +142     
+ Misses       1037     1021      -16

@alexandru alexandru merged commit ca3c61b into monix:master Sep 25, 2018
@alexandru alexandru modified the milestones: 3.0.0, 3.0.0-RC2 Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants