Skip to content

How to return execution to initial scheduler #983

@s-spindler

Description

@s-spindler

Hi all,

I have a question regarding the scheduling of background tasks.
On some requests that I proxy I would like to start an asynchronous task in the background.
The request should continue without waiting for the background task.

So far I have not found a way of continuing the request on the default scheduler after publishing the background task on my custom scheduler:

override fun filter(exchange: ServerWebExchange, chain: GatewayFilterChain): Mono<Void> {
    return Mono.just("bla")
            .publishOn(someCustomScheduler)
            .doOnNext {
                // do something expensive here
                println(it)
            }
            // how to return to default scheduler here?
            .flatMap {
                chain.filter(exchange)
            }
}

I can't find a way of getting a handle on the default scheduler. Is it possible to get it somehow?
Or is my approach wrong anyway?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions