Skip to content

Use Mono.empty() instead of a State with null value (when a state does not exist) #524

Description

@xiazuojie

Describe the proposal

Non-existing value

Project reactor does not allow null values. It has the concept of an empty stream to represent a non-existing value. It has the benefit of being null-safe.

When a state does not exist, current state API does not return an empty Mono. Instead, it returns a State object with its value set to null. It is not null-safe. It requires the client to do null check as follows:

        GetStateRequest request = new GetStateRequestBuilder("example-store", "test-key").build();
        Mono<State<String>> state = daprClient.getState(request, TypeRef.STRING).flatMap(
                it -> Mono.justOrEmpty(it.getValue()) // boilerplate code to check null
        );

I suggest getState() API returns Mono.empty() when a state does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions