Is There a Way to Use setTimeout in Gnome Shell Extension Code?

I am trying to code a gnome-shell extension. It uses Javascript. But one major problem when I want to use setTimeout() it tells me this in the log: ReferenceError: setTimeout is not defined, what I am going to reach here is I want to call a function in non-blocking way using setTimeout(). Maybe one of you has met this issue before or you may have a solution/alternative for me.

4

1 Answer

Just to capture this in an answer:

const Mainloop = imports.mainloop;

...

Mainloop.timeout_add(1000, () => log('one second later!'));

As seen here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest