Java Code Examples for reactor.core.publisher.Mono#using()

The following examples show how to use reactor.core.publisher.Mono#using() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public Mono<Task.Result> executeTask(TaskWithId taskWithId) {
    if (!cancelledTasks.remove(taskWithId.getId())) {
        Mono<Task.Result> taskMono = Mono.fromCallable(() -> runWithMdc(taskWithId, listener)).subscribeOn(taskExecutor);
        CompletableFuture<Task.Result> future = taskMono.toFuture();
        runningTask.set(Tuples.of(taskWithId.getId(), future));

        return Mono.using(
            () -> pollAdditionalInformation(taskWithId).subscribe(),
            ignored -> Mono.fromFuture(future)
                .onErrorResume(exception -> Mono.from(handleExecutionError(taskWithId, listener, exception))
    } else {
        return Mono.from(listener.cancelled(taskWithId.getId(), taskWithId.getTask().details()))
Example 2
Source Project: sdn-rx   File:    License: Apache License 2.0 5 votes vote down vote up
public Mono<Movie> findByTitle(String title) {
	return Mono.using(driver::rxSession,
		session -> Mono.from("MATCH (m:Movie {title: $title}) RETURN m", Values.parameters("title", title))
Example 3
Source Project: sdn-rx   File:    License: Apache License 2.0 5 votes vote down vote up
public Mono<Movie> save(Movie movie) {
	return Mono.using(driver::rxSession,
		session -> Mono.from("CREATE (m:Movie {title: $title, tagline: $tagline}) RETURN m",
				Values.parameters("title", movie.getTitle(), "tagline", movie.getTagline()))
Example 4
Source Project: reactor-netty   File:    License: Apache License 2.0 5 votes vote down vote up
static<S> Mono<Void> mockSendUsing(Connection c, Callable<? extends S> sourceInput,
		BiFunction<? super Connection, ? super S, ?> mappedInput,
		Consumer<? super S> sourceCleanup) {
	return Mono.using(
			s -> FutureMono.from(
			                      .writeAndFlush(mappedInput.apply(c, s))),
Example 5
Source Project: james-project   File:    License: Apache License 2.0 5 votes vote down vote up
private Mono<Void> processMail(MailQueueItem queueItem) {
    return Mono
            mail -> Mono.fromRunnable(() -> performProcessMail(queueItem, mail)),
Example 6
public Mono<BlobId> putAndComputeId(ObjectStorageBucketName bucketName, Blob initialBlob, Supplier<BlobId> blobIdSupplier) {
    return Mono.using(
        () -> copyToTempFile(initialBlob),
        file -> putByFile(bucketName, blobIdSupplier, file),
Example 7
public Mono<Void> save(BucketName bucketName, BlobId blobId, ByteSource content) {
    return Mono.using(content::openBufferedStream,
        stream -> save(bucketName, blobId, stream),
Example 8
public Mono<BlobId> save(BucketName bucketName, InputStream data, StoragePolicy storagePolicy) {
    HashingInputStream hashingInputStream = new HashingInputStream(Hashing.sha256(), data);
    return Mono.using(
        () -> new FileBackedOutputStream(FILE_THRESHOLD),
        fileBackedOutputStream -> saveAndGenerateBlobId(bucketName, hashingInputStream, fileBackedOutputStream),
Example 9
public Mono<Void> transferTo(Path dest) {
	return Mono.using(() ->, StandardOpenOption.WRITE),
			this::writeBody, this::close);