Skip to content

Using custom label leads to incorrect graph visualization #38

@sultazat

Description

@sultazat

The following code with custom label generates incorrect graph visualization:

import ru.fix.completable.reactor.graph.kotlin.Graph
import kotlin.random.Random

class ExampleGraph : Graph<ExamplePayload>() {

    private val generate = suspendHandler {
        Random.nextInt(-10, 10)
    }.withRoutingMerger router@{
        if (it == 0) {
            return@router Flow.ZERO
        }

        if (it < 0) {
            Flow.NEGATIVE
        } else {
            Flow.POSITIVE
        }
    }

    private val positive = suspendHandler { }.withoutMerger()
    private val negative = suspendHandler { }.withoutMerger()
    private val zero = suspendHandler { }.withoutMerger()

    private enum class Flow {
        POSITIVE,

        NEGATIVE,

        ZERO
    }

    init {
        payload().handleBy(generate)

        generate
            .on(Flow.POSITIVE).handleBy(positive)
            .on(Flow.NEGATIVE).handleBy(negative)
            .on(Flow.ZERO).handleBy(zero)

        positive.onAny().complete()
        negative.onAny().complete()
        zero.onAny().complete()

        coordinates()
            .pd(3, -126)
            .vx(negative, 33, 148)
            .vx(positive, -155, 143)
            .vx(zero, 261, 118)
            .vx(generate, 32, -50, 56, 31);
    }
}

Here is visualization:

telegram-cloud-photo-size-2-5352564785067176520-x

But if we will change generate vertex code to the following:

private val generate = suspendHandler {
        Random.nextInt(-10, 10)
    }.withRoutingMerger {
        if (it == 0) {
            return@withRoutingMerger Flow.ZERO
        }

        if (it < 0) {
            Flow.NEGATIVE
        } else {
            Flow.POSITIVE
        }
    }

everything is ok:
telegram-cloud-photo-size-2-5352564785067176524-x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions