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
Fix #123: introduce Async.asyncF #248
Conversation
Codecov Report
@@ Coverage Diff @@
## master #248 +/- ##
==========================================
+ Coverage 89.18% 89.31% +0.13%
==========================================
Files 58 57 -1
Lines 1525 1544 +19
Branches 157 153 -4
==========================================
+ Hits 1360 1379 +19
Misses 165 165 |
Nice :) One question, that pure Promise above still can't be cancellable, right? We'd need a |
I'm sorry, I lost track of whether we allow auto-cancellable |
@SystemFw for one We can afford to do that, because in case of error we only need to report it, or otherwise we don't care about the Plus if we try really hard, we might discover that it isn't needed. The |
@durban indeed it doesn't work, but not for the stated reason — what you're saying would work due to I don't want to fix that now, so I've replaced the sample. @SystemFw the new |
@alexandru Nice, thank you :) Might be worth a mention in the scaladoc perhaps? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks nice.
|
||
trait AllSyntax | ||
extends ConcurrentEffect.ToConcurrentEffectOps | ||
with Effect.ToEffectOps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not have referential transparency-breaking methods as a syntax extension, at least as a default one.
On the other hand, I would definitely like utilities we have - like timeoutTo
, not sure if there are many of those - available as syntax extensions.
And if I can ask for more, writing Sync[F].delay { ... }
is a bit mouthful, I would very much appreciate having delay[F] { ... }
as a global symbol (maybe under a separate import).
And ToBracketOps
, we should definitely have that here-ish :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oleg-py what syntax do we have in there that is breaking RT?
I’m not interested in adding extension methods that aren’t on these type-classes. The reason is that they are hard to maintain.
Notice that we did not exposed these until now and nobody cared 😉
Also Bracket
isn’t a @typeclass
so it doesn’t have syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err, sorry, I meant to say methods intended to be used near the "end of the world", like runCancelable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What’s wrong with it? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's nothing wrong except for IDE autocomplete pollution :) (Concurrent)Effect
are useful in advanced interop scenarios, and I tend to use them way less than delay
or async
, esp. since we won't even need it in upcoming fs2 version.
Cats is very good at giving a la carte imports for stuff that I want :)
Right, Bracket
can't have @typeclass
due to having more than one type parameter. I still believe the syntax for Bracket
is quite important, more so than for ConcurrentEffect
🙂
@SystemFw I've added mentions in ScalaDoc too. |
@oleg-py I cannot address your complaints on But I don't want to bother with that and we can add it later. So either I fix the |
@alexandru fine by me. If we merge this soon, I can roll out a syntax PR/proposal quickly enough :) |
LGTM 👍
The only thing I failed to see is whether we want to reflect this in the laws? |
We can’t add laws for the behavior of that |
Fixes #123 — This PR adds a variant of the
async
builder that suspends side effects in the provided callback.This is useful for eliminating the need for
Effect
in many cases where currently it would be required. As an example given in the ScalaDocs, currently this isn't possible withoutEffect
:This works for cancelable stuff too, behaving like
F.suspend
actually, except that the result needs to be signaled via the provided callback:Gotcha: the returned
F[Unit]
cannot throw errors. If it does, the behavior is undefined — because the only way to signal errors is via the provided callback and we cannot call the callback without risking a contract violation or without expensive synchronization.For
IO
the implementation will log the error via the globalLogger
and other implementations are supposed to log the error somewhere too. ForIO
in particular, we could signal the error via the provided callback, however we don't know if that piece of synchronization will stay there forever, plus I don't want to encourage unhealthy practices becauseIO
behaves in a certain way. The callback provided byAsync
is not supposed to be called concurrently from multiple places, if it gets called like that then the behavior is undefined.Other fixes:
Async#shift
completely, it was deprecated in 0.10 and now we are retiring itcats.effect.implicits
for getting syntax for our type classes (not sure if I did the right thing)