Skip to content

Instantly share code, notes, and snippets.

@okram
Created May 23, 2014 15:34
Show Gist options
  • Save okram/2d0f850f81de92a95304 to your computer and use it in GitHub Desktop.
Save okram/2d0f850f81de92a95304 to your computer and use it in GitHub Desktop.
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