Added an extra api call that omits the default result

Signed-off-by: Titouan Vervack <titouan.vervack@sigasi.com>
This commit is contained in:
Titouan Vervack 2018-06-11 11:08:40 +02:00
parent 69e9f07aca
commit 528de63088
2 changed files with 57 additions and 3 deletions

View file

@ -50,7 +50,24 @@ public interface IReadAccess<State> {
return work.exec(state);
});
}
/**
* Tries to get a read-only copy of the State and execute {@code work} on it.
*
* @param work Work to execute on the State
*
* @return The result of executing {@code work}, or
* null if the State is null
* @since 2.15
*/
default <Result> Result tryReadOnly(IUnitOfWork<Result, State> work) {
return readOnly((state) -> {
if (state == null) return null;
return work.exec(state);
});
}
/**
* Tries to get a read-only copy of the State and execute {@code work} on it.
*
@ -116,7 +133,27 @@ public interface IReadAccess<State> {
return work.exec(state);
});
}
/**
* Tries to get a read-only copy of the State and execute {@code work} on it.
* Cancels all cancelable readers before executing the {@link IUnitOfWork}.
* For interactive jobs that need fastest possible execution.
*
* @param work Work to execute on the State
*
* @return The result of executing {@code work}, or
* null if the State is null
* @since 2.15
* @see CancelableUnitOfWork
*/
default <Result> Result tryPriorityReadOnly(IUnitOfWork<Result, State> work) {
return priorityReadOnly((state) -> {
if (state == null) return null;
return work.exec(state);
});
}
/**
* Tries to get a read-only copy of the State and execute {@code work} on it.
* Cancels all cancelable readers before executing the {@link IUnitOfWork}.

View file

@ -49,7 +49,24 @@ public interface IWriteAccess<State> {
return work.exec(state);
});
}
/**
* Tries to modify the State by executing {@code work} on it.
*
* @param work Work that modifies the State
*
* @return The result of executing {@code work}, or
* null if the State is null
* @since 2.15
*/
default <Result> Result tryModify(IUnitOfWork<Result, State> work) {
return modify((state) -> {
if (state == null) return null;
return work.exec(state);
});
}
/**
* Tries to modify the State by executing {@code work} on it.
*