T - the Mono data typepublic class LockedMono.LockedMonoBuilder<T> extends Object
Example:
Lock lock = new ReactiveLock();
mono
.map(t -> operationsRegardlessOfTheLock(t))
/* Begin the lock scope */
.as(Lock::begin)
.map(t -> operationsWithLockAcquired(t))
.flatMap(s -> operationsWithLockAcquired(s))
/* Confirm to apply the above two transformations under the lock */
.with(lock);
The above code is actually equivalent to the following code using Lock.withLock(Supplier).
Lock lock = new ReactiveLock();
mono
.map(t -> operationsRegardlessOfTheLock(t))
/* Begin the lock scope */
.flatMap(t -> lock.withLock(() ->
Mono.just(t)
.map(t -> operationsWithLockAcquired(t))
.flatMap(s -> operationsWithLockAcquired(s))
).next());
If you want more complex operators, please just wrap them in flatMap(Function).
| Modifier and Type | Method and Description |
|---|---|
<S> LockedMono.LockedMonoBuilder<S> |
flatMap(Function<T,Mono<S>> flatMapper)
Calling
Mono.flatMap(Function) of the internal mono, with the lock held |
<S> LockedMono.LockedMonoBuilder<S> |
map(Function<T,S> mapper)
Calling
Mono.map(Function) of the internal mono, with the lock held |
Mono<T> |
with(Lock lock)
Transforms the builder into a
Mono, with previous transformations
gathered into the lock scope with Lock.withLock(Supplier) |
Mono<T> |
withR(RWLock lock)
Transforms the builder into a
Mono, with previous transformations
gathered into the lock scope with RWLock.withRLock(Supplier) |
public <S> LockedMono.LockedMonoBuilder<S> map(Function<T,S> mapper)
Mono.map(Function) of the internal mono, with the lock heldS - the transformed value typemapper - the synchronous transforming FunctionLockedMono.LockedMonoBuilderpublic <S> LockedMono.LockedMonoBuilder<S> flatMap(Function<T,Mono<S>> flatMapper)
Mono.flatMap(Function) of the internal mono, with the lock heldS - the transformed value typeflatMapper - the synchronous transforming FunctionLockedMono.LockedMonoBuilderpublic Mono<T> with(Lock lock)
Mono, with previous transformations
gathered into the lock scope with Lock.withLock(Supplier)lock - the lockMono with previous locking, transformations and unlocking applied