Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using custom label leads to incorrect graph visualization #38

Open
sultazat opened this issue Dec 3, 2020 · 0 comments
Open

Using custom label leads to incorrect graph visualization #38

sultazat opened this issue Dec 3, 2020 · 0 comments

Comments

@sultazat
Copy link

sultazat commented Dec 3, 2020

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

@sultazat sultazat changed the title Using labels Using custom label leads to incorrect graph visualization Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant