Rafal Piotrowski
08/19/2019, 12:43 PMDeferred
class from kotlinx.coroutines
, sample code is below. As you can see I have DemoService
and DemoRouting
which have no suspend method and are parametrized with type F
. I define F
as IO
when the server is created (so on the end of the world ;)). I could use different monad (e.g. Try
) after implementing the Deferrable
interface. Please let me know what you think about this approach. @Bob Glamm, this is a little bit different than using Async
directly as we spoken recently, there is a separate typeclass to transform value into deffered value.simon.vergauwen
08/19/2019, 12:58 PMIO
-> Deferred
-> suspend
. Can you not just use IO
-> suspend
?simon.vergauwen
08/19/2019, 12:58 PMBob Glamm
08/19/2019, 12:58 PMIO.suspended
simon.vergauwen
08/19/2019, 12:59 PMDeferred
looks like the wrong data type here. No reason to introduce eagerness here when you can get away with keeping it pure by using suspend
instead.simon.vergauwen
08/19/2019, 1:00 PMSuspendable
if needed for IO
. When you have kotlinx
on the classpath you can also implement a cancellable version using suspendCoroutineCancelable
.Rafal Piotrowski
08/19/2019, 1:04 PMSuspendable
is not present in 0.9.0 I can refactor it to Suspendable
when 0.10.0 will be released 😄Bob Glamm
08/19/2019, 1:24 PMSuspendable
in 0.10.0-SNAPSHOT?Bob Glamm
08/19/2019, 1:24 PMsuspended()
Rafal Piotrowski
08/19/2019, 1:25 PMsimon.vergauwen
08/19/2019, 1:25 PMSuspendable
is not there. It’s a temporary typeclass in that snippetsimon.vergauwen
08/19/2019, 1:25 PMsuspended()
will come to the Arrow Fx typeclass hierarchy in next releases. Most likely in Effect
.Bob Glamm
08/19/2019, 1:25 PMsimon.vergauwen
08/19/2019, 1:27 PMBob Glamm
08/19/2019, 1:29 PMsimon.vergauwen
08/19/2019, 1:29 PMBob Glamm
08/19/2019, 1:29 PMBob Glamm
08/19/2019, 1:30 PMsimon.vergauwen
08/19/2019, 1:54 PMRafal Piotrowski
08/20/2019, 6:43 AMSuspendable
(see code snippet below). In 0.10.0 I should be able to smoothly switch to Suspendable
from Arrow. Please don't ask why I used this Deferred
instead of suspend function directly, I have no idea 😉. Solution with with Suspendable
is simpler and it is more easy to refactor for 0.10.0 in future.simon.vergauwen
08/20/2019, 6:46 AMRafal Piotrowski
08/20/2019, 6:57 AMsimon.vergauwen
08/20/2019, 7:17 AMBob Glamm
08/22/2019, 1:43 AMcall
should go. In my last attempt I tried to compose PipelineContext
with Async<F>
so that the program in Async<F>
could decide what to do with the response. In the example above, the return type of work.suspended()
would need to be robust enough for the code in the get(...) { ... }
block to handle the complete response via methods on call
.Bob Glamm
08/22/2019, 1:43 AMsimon.vergauwen
08/22/2019, 6:25 AMBob Glamm
08/22/2019, 1:11 PM(arg...) -> Unit
within the handler are common to form an HTTP response. For instance, the following set various HTTP response headers:
response.etag("33a64df551425fcc55e4d42a148795d9f25f89d4")
response.lastModified(ZonedDateTime.now())
response.contentLength(1024L)
response.cacheControl(CacheControl.NoCache(CacheControl.Visibility.Private))
response.expires(LocalDateTime.now())
response.contentRange(1024L until 2048L, 4096L)
Methods with similar type signatures exist for setting the response status and emitting the response body. In terms of how this relates to `Kind<F, Response>`: F
is usually at least as powerful as MonadThrow
and the arguments supplied to the response methods are typically dependent on failure or success, so .attempt()/.fold()
or .catch()/.handleErrorWith()
seems reasonable, but in both of those cases the object in the handler (call
) needs to be available within the effect. The other alternative I can think of is that Response
is made robust enough so there is a direct mapping between Response
and all of the methods on response
, but it seems difficult and error-prone to re-encapsulate the entire response
object.