Last active
April 8, 2019 17:04
-
-
Save mmimica/6981ccc0603901f7f3da6d70e4062886 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WindowedInvoker<T, R> { | |
private final Semaphore semaphore = new Semaphore(windowSize); | |
private class ReleasingCallback<R> implements Consumer<R> { | |
private final Consumer<R> delegate; | |
@Override | |
public void accept(R result) { | |
semaphore.release(); | |
delegate.accept(t); | |
} | |
} | |
public void invoke(Consumer<List<T>> consumer, List<T> batch, Consumer<R> callback) { | |
semaphore.acquire(); | |
consumer.accept(batch, new ReleasingCallback(semaphore, callback)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment