Skip to content

Recommended way to deal with "Runaway clock detected"? #29

@trusktr

Description

@trusktr

Here's a small recursive example:

const word = S.data('John')
const number = S.data(123)

S.root(() => {
    S(() => {
        if (word() == 'mary') {
            number(number() + 1)
        }
    })  

    S(() => {
        console.log(number())
    })
})


word('blah')
word('mary')
word('foo')

It causes the first computation to run infinitely (until the error) because it reads and sets the number in the same computation.

What's you advice for these sorts of situations in general?

In this case, maybe the hypothetical user meant:

const word = S.data('John')
const number = S.data(123)

S.root(() => {
    S(() => {
        console.log(number())
    })
})

S.on(word, () => {
    if (word() === 'mary') {
        number(number() + 1)
    }
})

word('blah')
word('mary') // logs the new number
word('foo')

Curious to know in what sorts of cases we might run into the infinite recursion, and how to deal with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions