Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tonivade committed Jul 2, 2024
1 parent f2da153 commit 4b778fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,21 +472,21 @@ static <R, E, A, B> PureIO<R, E, B> bracket(Kind<PureIO<R, E, ?>, ? extends A> a

PureIOConnection cancellable = PureIOConnection.cancellable();

Promise<Either<E, A>> promise = runAsync(env, acquire.fix(PureIOOf::toPureIO), cancellable);
Promise<Either<E, A>> promise = runAsync(env, acquire.fix(Kind::narrowK), cancellable);

promise
.onFailure(e -> callback.accept(Try.failure(e)))
.onSuccess(either -> either.fold(error -> {
callback.accept(Try.success(Either.left(error)));
return Unit.unit();
}, resource -> {
Promise<Either<E, B>> runAsync = runAsync(env, use.apply(resource).fix(PureIOOf::toPureIO), cancellable);
Promise<Either<E, B>> runAsync = runAsync(env, use.apply(resource).fix(Kind::narrowK), cancellable);

runAsync
.onFailure(e -> callback.accept(Try.failure(e)))
.onSuccess(result -> {

Promise<Either<E, Unit>> run = runAsync(env, release.apply(resource).fix(PureIOOf::toPureIO), cancellable);
Promise<Either<E, Unit>> run = runAsync(env, release.apply(resource), cancellable);

run.onComplete(ignore -> result.fold(error -> {
callback.accept(Try.success(Either.left(error)));
Expand All @@ -510,7 +510,7 @@ static <R, E> PureIO<R, E, Unit> unit() {

PureIO<?, ?, Unit> UNIT = PureIO.pure(Unit.unit());

private static <R, E, A> Promise<Either<E, A>> runAsync(@Nullable R env, PureIO<R, E, A> current, PureIOConnection connection) {
private static <R, E, A> Promise<Either<E, A>> runAsync(@Nullable R env, Kind<PureIO<R, E, ?>, A> current, PureIOConnection connection) {
return runAsync(env, current, connection, new CallStack<>(), Promise.make());
}

Expand Down
8 changes: 4 additions & 4 deletions monad/src/main/java/com/github/tonivade/purefun/monad/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ static <T, R> IO<R> bracket(Kind<IO<?>, ? extends T> acquire,

IOConnection cancellable = IOConnection.cancellable();

Promise<? extends T> promise = runAsync(acquire.fix(IOOf::toIO), cancellable);
Promise<? extends T> promise = runAsync(acquire, cancellable);

promise
.onFailure(error -> callback.accept(Try.failure(error)))
.onSuccess(resource -> runAsync(use.apply(resource).fix(IOOf::toIO), cancellable)
.onComplete(result -> runAsync(release.apply(resource).fix(IOOf::toIO), cancellable)
.onSuccess(resource -> runAsync(use.apply(resource), cancellable)
.onComplete(result -> runAsync(release.apply(resource), cancellable)
.onComplete(ignore -> callback.accept(result))
));

Expand Down Expand Up @@ -421,7 +421,7 @@ static <A, B> IO<Tuple2<A, B>> tuple(Executor executor, Kind<IO<?>, ? extends A>
return parMap2(executor, fa, fb, Tuple::of);
}

private static <T> Promise<T> runAsync(IO<T> current, IOConnection connection) {
private static <T> Promise<T> runAsync(Kind<IO<?>, T> current, IOConnection connection) {
return runAsync(current, connection, new CallStack<>(), Promise.make());
}

Expand Down

0 comments on commit 4b778fc

Please sign in to comment.