Repository navigation
Cleanup combinators - #1102
Cleanup combinators#1102
Conversation
| * @return | ||
| * A computation that produces the result of this computation with Async and Resource effects | ||
| */ | ||
| inline def forkScoped( |
There was a problem hiding this comment.
We should have a similar method in Async
| * Asynchronous computation with handled Emit that can fail with Abort[Closed] | ||
| */ | ||
| def emitToChannel(channel: Channel[A])(using Tag[A], Flat[B], Frame): B < (S & Async & Abort[Closed]) = | ||
| effect.foreachEmit(a => channel.put(a)) |
There was a problem hiding this comment.
this could use a batched channel put
There was a problem hiding this comment.
This is for an unchunked emit, though
| * @return | ||
| * A computation that produces the result of this computation | ||
| */ | ||
| def debugTrace(using Frame): A < S = Debug.trace(effect) |
| * @return | ||
| * A computation that produces the result of this computation with Async effect | ||
| */ | ||
| def repeat(backoff: Int => Duration, limit: Int)(using Flat[A], Frame): A < (S & Async) = |
There was a problem hiding this comment.
we have similar methods in Clock.repeat* now. It'd be nice to follow the same semantics and naming.
There was a problem hiding this comment.
I'll take a look
There was a problem hiding this comment.
Made some updates:
- Got rid of some of the more complicated methods, as these can be accomplished with
Clockand clutter the namespace - Changed the names of the two remaining
repeatoverloads that useDurationand returnAsyncwithrepeatAtInterval - Kept the simpler
repeatandrepeatWhile/repeatUntil, since these don't useDuration/Schedule/Asyncand so don't really reflect theClockAPI
| * @return | ||
| * Stream representation of original effect | ||
| */ | ||
| def emitToStream: Stream[A, S] = Stream(effect) |
There was a problem hiding this comment.
Can this be inline? Should help make sure it's suspended.
There was a problem hiding this comment.
Yes, but I don't understand how that ensures it's suspended
There was a problem hiding this comment.
Stream.apply is inlined and takes a by-name function. That'd require a separate group of extension methods where effect is also declared as inline. I'm not sure it's worth it, especially given that "someValue.doSomething" typically implies the value being evaluated before the method call. We have pipe that breaks this assumption but I think it's more justifiable.
There was a problem hiding this comment.
Ah you're correct. Extension methods do break this assumption.
| * @return | ||
| * A computation that produces the result of this computation | ||
| */ | ||
| def debugValue(using Frame): A < S = Debug(effect) |
There was a problem hiding this comment.
That creates a name class with the debug package, which I'd like to avoid.
| * A computation that produces the result of the last successful execution before the condition becomes false | ||
| */ | ||
| def repeatWhile[S1](fn: A => Boolean < S1)(using Flat[A], Frame): A < (S & S1) = | ||
| Loop(()): _ => |
There was a problem hiding this comment.
I need to think of a signature for this common pattern...
| def ensuring(finalizer: => Any < Async)(using Frame): A < (S & Resource & IO) = | ||
| Resource.ensure(finalizer).andThen(effect) |
There was a problem hiding this comment.
I wonder if ensure should have an ensureWith as well?
There was a problem hiding this comment.
I'll add an issue for this
Co-authored-by: Adam Hearn <[email protected]>
Co-authored-by: Adam Hearn <[email protected]>
|
I think latest updates address all PR review comments |
A STARTTLS/TLS client on the io_uring backend could place its handshake Finished flight and its first post-upgrade application record on two concurrent send SQEs for the same fd. io_uring can reap those out of order (liburing #1102), reordering the bytes on the wire, so the peer read a byte-shifted record and aborted the connection with a bad_record_mac fatal alert. This made a kyo-net STARTTLS client fail against a standard TLS server (reproduced deterministically against openssl) and flaked the cross-backend STARTTLS test under load. The handshake's final flight is sent through the raw send tail (rawPending/rawSendInFlight, while handle.tls is still Absent) while post-upgrade application data uses the TLS send tail (pendingCipher/sendInFlight); the two single-in-flight guards were independent, so a TLS send could be submitted while a raw send was still in flight. The raw->TLS transition is one-way (handle.tls becomes Present at completion and every later write routes through writeTls), so flushTls now defers while the raw tail is in flight or has unsent bytes, and onRawSendComplete flushes the TLS tail once the raw tail drains. At most one send SQE per fd is in flight across the transition. Also fail, rather than strand, a TLS engine read op that throws on both posix drivers: the op held a pending read promise, so a bare escape hung the connection to the leaf timeout instead of tearing it down with the engine error.
Problem
Abort[Throwable]Loop, e.g.)Solution
Combinators.scalainto separate files according to effect typeretry(s: Schedule),retry(i: Int), andretryForeverfor the entireAbortunionforAbort[E].retry(s: Schedule),forAbort[E].retry(i: Int), andforAbort[E].retryForeverfor a specific error typeretryForever(new) handlesAbortcompletelyNotes
Kyo.sleepForeverwhich I've found useful in a couple of cases