{"id":1149,"date":"2023-03-30T01:55:54","date_gmt":"2023-03-29T23:55:54","guid":{"rendered":"https:\/\/greladesign.co\/blog\/?p=1149"},"modified":"2023-03-30T01:55:54","modified_gmt":"2023-03-29T23:55:54","slug":"browserprioritytimers-npm-module","status":"publish","type":"post","link":"https:\/\/greladesign.co\/blog\/2023\/03\/30\/browserprioritytimers-npm-module\/","title":{"rendered":"BrowserPriorityTimers npm module"},"content":{"rendered":"\n<p>I&#8217;ve prepared <a rel=\"noreferrer noopener\" href=\"https:\/\/www.npmjs.com\/package\/browser-priority-timers\" target=\"_blank\">npm package <\/a>with the <code>BrowserPriorityTimers<\/code> class. It gives you ability to use timers that will not be throttled by the browser. This maybe useful at times when you want to keep your timers execute without interruption even when the tab is inactive. You can install it with the <code>npm i browser-priority-timers<\/code> command.<\/p>\n\n\n\n<!--more-->\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">if<\/span> (!timers.workerAvailable()) {\n  <span class=\"hljs-built_in\">console<\/span>.warn(<span class=\"hljs-string\">\"Priority timers are not available for this browser\"<\/span>);\n} <span class=\"hljs-keyword\">else<\/span> {\n  <span class=\"hljs-built_in\">console<\/span>.info(<span class=\"hljs-string\">\"Priority timers are available\"<\/span>);\n  timers.setTimeout(<span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n    <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"setTimeout on worker.\"<\/span>);\n  }, <span class=\"hljs-number\">1000<\/span>);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Whenever you need a timer with a priority use the one provided by the <code>BrowserPriorityTimers<\/code> class. I hope you enjoy it.<\/p>\n\n\n\n<h3>Source code<\/h3>\n\n\n\n<ul class=\"wp-container-2 wp-block-social-links has-large-icon-size is-style-pill-shape\"><li class=\"wp-social-link wp-social-link-github wp-block-social-link\"><a href=\"https:\/\/github.com\/LukaszGrela\/browser-priority-timers\" aria-label=\"Source code\" rel=\"noopener nofollow\" target=\"_blank\" class=\"wp-block-social-link-anchor\"> <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z\"><\/path><\/svg><\/a><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve prepared npm package with the BrowserPriorityTimers class. It gives you ability to use timers that will not be throttled by the browser. This maybe useful at times when you want to keep your timers execute without interruption even when &hellip; <a href=\"https:\/\/greladesign.co\/blog\/2023\/03\/30\/browserprioritytimers-npm-module\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":""},"categories":[362,356],"tags":[366,365,357,364],"_links":{"self":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/1149"}],"collection":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/comments?post=1149"}],"version-history":[{"count":3,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/1149\/revisions"}],"predecessor-version":[{"id":1152,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/1149\/revisions\/1152"}],"wp:attachment":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/media?parent=1149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/categories?post=1149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/tags?post=1149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}