-
Notifications
You must be signed in to change notification settings - Fork 50
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
Parallelism not working as expected #196
Comments
This actually has nothing to do with Calling The difference between calling The problem is that the PR typelevel/cats#1618 should solve this in the next Cats version. |
Now that the Cats PR is merged, I am going ahead and close this issue. If you want to try this before the next Cats release, you can provide your own val foo: FreeS[Validation.Op, (Boolean, Boolean)] =
(minSize(3) |@| hasNumber).tupled.freeS
// a bit more work than foo.exec[ParValidator] ...
val parValidatorMonad = kleisliMonad[Future, String]
val parInterpreter: ParInterpreter[Validation.Op, ParValidator] =
interpretAp(parValidatorMonad, implicitly[Algebra.Validation.Handler[ParValidator]]))
val result: ParValidator[(Boolean, Boolean)] = foo.foldMap(parInterpreter)
def kleisliMonad[F[_], A](implicit F: Monad[F]) = new Monad[Kleisli[F, A, ?]] {
def flatMap[B, C](fa: Kleisli[F, A, B])(f: B => Kleisli[F, A, C]): Kleisli[F, A, C] =
fa.flatMap(f)
def tailRecM[B, C](b: B)(f: B => Kleisli[F, A, Either[B, C]]): Kleisli[F, A, C] =
Kleisli[F, A, C]({ a => F.tailRecM(b) { f(_).run(a) } })
def pure[B](x: B): Kleisli[F, A, B] =
Kleisli.pure[F, A, B](x)
override def ap[B, C](f: Kleisli[F, A, B => C])(fa: Kleisli[F, A, B]): Kleisli[F, A, C] =
fa.ap(f)
override def product[B, C](fb: Kleisli[F, A, B], fc: Kleisli[F, A, C]): Kleisli[F, A, (B, C)] =
Kleisli(a => F.product(fb.run(a), fc.run(a)))
override def map[B, C](fa: Kleisli[F, A, B])(f: B => C): Kleisli[F, A, C] =
fa.map(f)
} |
@peterneyens Compilation Errors:
|
@abdheshkumar Specifying the type of the val parValidatorMonad: Monad[ParValidator] = KleisliMonad.kleisliMonad[Future, String] |
@peterneyens |
We recently found the weird behavior of parallelism with freestyle. Details below:
Algebra:
Interpreter:
Test1:
Tes2:
Output:(determinism)
We found that
hasNumber
is blocked tillminSize
is completed. So I think the issue is betweenmap
andtupled.freeS
.If you want to run a complete program, you can clone it from here https://github.com/abdheshkumar/freestyle-example/blob/master/src/test/scala/FreeFutureTest.scala
The text was updated successfully, but these errors were encountered: