Search in sources :

Example 1 with NanoTimeProvider

use of me.retrodaredevil.action.node.util.NanoTimeProvider in project solarthing by wildmountainfarms.

the class TimeoutActionNode method createAction.

@Override
public Action createAction(ActionEnvironment actionEnvironment) {
    NanoTimeProviderEnvironment nanoTimeProviderEnvironment = actionEnvironment.getInjectEnvironment().get(NanoTimeProviderEnvironment.class);
    NanoTimeProvider nanoTimeProvider = nanoTimeProviderEnvironment.getNanoTimeProvider();
    return Actions.createDynamicActionRunner(() -> {
        final Long lastFireNanos = this.lastFireNanos;
        long nowNanos = nanoTimeProvider.getNanos();
        if (lastFireNanos == null || nowNanos - lastFireNanos > timeoutNanos) {
            this.lastFireNanos = nowNanos;
            return actionNode.createAction(actionEnvironment);
        }
        return Actions.createRunOnce(() -> {
        });
    });
}
Also used : NanoTimeProviderEnvironment(me.retrodaredevil.action.node.environment.NanoTimeProviderEnvironment) NanoTimeProvider(me.retrodaredevil.action.node.util.NanoTimeProvider)

Aggregations

NanoTimeProviderEnvironment (me.retrodaredevil.action.node.environment.NanoTimeProviderEnvironment)1 NanoTimeProvider (me.retrodaredevil.action.node.util.NanoTimeProvider)1