Skip to content

Commit

Permalink
#265 ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 29, 2017
1 parent 2f1fe94 commit 3f1bc7e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/org/cactoos/func/AsyncFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import org.cactoos.Func;

/**
Expand Down Expand Up @@ -52,17 +53,32 @@ public final class AsyncFunc<X, Y> implements Func<X, Future<Y>> {
*/
private final Func<X, Y> func;

/**
* The threads.
*/
private final ThreadFactory factory;

/**
* Ctor.
* @param fnc The proc
*/
public AsyncFunc(final Func<X, Y> fnc) {
this(fnc, Executors.defaultThreadFactory());
}

/**
* Ctor.
* @param fnc The proc
* @param fct Factory
*/
public AsyncFunc(final Func<X, Y> fnc, final ThreadFactory fct) {
this.func = fnc;
this.factory = fct;
}

@Override
public Future<Y> apply(final X input) throws Exception {
return Executors.newSingleThreadExecutor().submit(
return Executors.newSingleThreadExecutor(this.factory).submit(
() -> this.func.apply(input)
);
}
Expand Down

0 comments on commit 3f1bc7e

Please sign in to comment.