Call JS fn after time delay in Seed

In Firebase Auth, when you create a new user account it logs them in automatically, but without a displayName. If I call firebase.auth().currentUser.displayName (in JS) too quickly, I get null. I need to delay a couple seconds at least and then retrieve the name. I could do this in JS with setTimeout, but I’d like to do as much as possible in Seed.

What is the proper way to call a function after a time delay in Seed? Elm has a mechanism like this for its update function:

Process.sleep time
  |> Task.perform (\_ -> DelayedMsg)

Something similar in Seed?

There isn’t dedicated API for this, but you can leverage gloo's TimeoutFuture - see example in the Seed repo.

1 Like

@MartinKavik this seems perfect! Unfortunately, I can’t seem to use the gloo_timers crate. In my Cargo.toml, I have:

gloo-timers = "^0.2.0"

In, I have:

use gloo_timers::future::TimeoutFuture;

I get a compiler error, "could not find future in gloo_timers". Strangely, in VSCode with RLS, as I type gloo_timers::, I get a dropdown that includes future. After typing :: again, I get a dropdown that includes TimeoutFuture. So I get code completion, but the compiler can’t see it…

I’m using the quickstart’s Makefile.toml.

Probably only missing feature flag -

1 Like

@MartinKavik, futures feature worked!

There is now in the master and it will be included in the next Seed version.

1 Like