Satyam Agarwal
01/23/2020, 2:15 PMTry { … }.toEither()
with IO { … }.attempt().unsafeRunSync()
in the clients/repositories
2. Start Replacing Either from services with IO and remove unsafeRunSync()
and bring it to services.
3. Eventually remove unsafeRunSync()
and bring them finally to controllers.
4. And finally get rid of springboot ❤️
I have worked with unsafeRunSync
before in production for very small things (mostly one time things like migrations, imports/exports where I couldn’t do without springboot 💢), so I am comfortable and have not seen any problems, but with above, my apis can get affected, consequently my user-base.
I am basically wondering about this line from doc
**NOTE** this function is intended for testing, it should never appear in your mainline production code!
Can you guys help me with deciding if this makes sense and is sane thing to do, and what kind of problems I can see with this approach.simon.vergauwen
01/23/2020, 2:26 PMsuspend()
.
If you require blocking the Thread
to await the result unsafeRunSync
is fine, but like you already mention in your migration plan you will always prefer to avoid that.simon.vergauwen
01/23/2020, 2:26 PMsuspend fun controllerEdge(): A = ioOfA.suspended()
that would also work on the edge of your controllers.simon.vergauwen
01/23/2020, 2:27 PME
into IO
so in the future you’ll also be able to do suspend fun controllerEdge(): Either<DomainError, A> = ioOfA.suspended()
simon.vergauwen
01/23/2020, 2:27 PMsuspend () -> A == IO<A>
suspend () -> Either<E, A> == IO<E, A>
simon.vergauwen
01/23/2020, 2:28 PMSatyam Agarwal
01/23/2020, 2:32 PMunsafeRunSync()
, its blocked.
However, since the whole application is synchronous, and eagerly evaluated, it shouldn’t matter right ?
I am not so good at threads handling.simon.vergauwen
01/23/2020, 2:32 PMSatyam Agarwal
01/23/2020, 2:33 PM