ru-fix / completable-reactor

CompletableReactor framework makes it easier to create business flows that have concurrently running parts and complex execution branching.
https://ru-fix.github.io/completable-reactor
MIT License
12 stars 2 forks source link

Using custom label leads to incorrect graph visualization #38

Open sultazat opened 3 years ago

sultazat commented 3 years ago

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