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

Confused by example code in the docmentation #802

Open
geohuz opened this issue Jan 23, 2024 · 1 comment
Open

Confused by example code in the docmentation #802

geohuz opened this issue Jan 23, 2024 · 1 comment

Comments

@geohuz
Copy link

geohuz commented Jan 23, 2024

The following example code is from the documentation in the clearTimeout section, I added a log to see the effect:

let closeHackerNewsTab = () => Js.log("close")

let timer = ref(Js.Nullable.null)

let work = () => closeHackerNewsTab()

let procrastinate = mili => {
  Js.Nullable.iter(timer.contents, (. timer) => {
    Console.log("timer cleared")
    Js.Global.clearTimeout(timer)
  })
  timer := Js.Nullable.return(Js.Global.setTimeout(work, mili))
}

procrastinate(2000)

I'm confused by the clearTimeout part coz it doesn't get triggered, so why do we care about it anyway?

@fhammerschmidt
Copy link
Collaborator

If you called procrastinate again, the old timer gets cleared first.
But that example is quite old from the old legacy Js module. Please use Rescript Core instead.

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

2 participants