Created
May 23, 2014 15:34
-
-
Save okram/2d0f850f81de92a95304 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 TimeLimitStep<S> extends MapStep<S, S> { | |
private final AtomicLong startTime = new AtomicLong(-1); | |
public TimeLimitStep(final Traversal traversal, final long timeLimit) { | |
super(traversal); | |
super.setFunction(traverser -> { | |
if (this.startTime.get() == -1l) | |
this.startTime.set(System.currentTimeMillis()); | |
if ((System.currentTimeMillis() - this.startTime.get()) >= timeLimit) | |
throw FastNoSuchElementException.instance(); | |
return traverser.get(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment