From ad399c96486919c1c3839e01c9a082bc185e388b Mon Sep 17 00:00:00 2001 From: Antonio Stoilkov Date: Mon, 18 Mar 2024 13:40:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20rewrite=20alternatives=20?= =?UTF-8?q?=E2=86=92=20`scheduler.postTask()`=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/readme.md b/readme.md index d125a1f..d19a752 100644 --- a/readme.md +++ b/readme.md @@ -121,15 +121,7 @@ Web Workers are a great fit if you have: 1) heavy algorithm (e.g. image processi ### `scheduler.postTask()` -[`scheduler.postTask()`](https://developer.mozilla.org/en-US/docs/Web/API/Scheduler/postTask) is available in some browsers today. `postTask` is a great alternative, you just need to have a better understanding on its inner workings. `main-thread-scheduling` aims to be easier to use. For example, `main-thread-scheduling` uses the `isInputPending()` API to ensure the UI doesn't freeze when the user interacts with the page (if you use `scheduler.postTask()` you will need to do that manually). Also, if you have running animations while running your tasks, you will see `main-thread-scheduling` perform better. - -If you want the benefits of `main-thread-scheduling`, but you prefer the callback based `postTask()` API/thinking model, then here is an implementation of `postTask()` using `yieldOrContinue()`: -```ts -async function postTask(callback: () => void | Promise) { - await yieldOrContinue('interactive') - await callback() -} -``` +[`scheduler.postTask()`](https://developer.mozilla.org/en-US/docs/Web/API/Scheduler/postTask) is available in some browsers today. `postTask()` and `main-thread-scheduling` share some commonalities. You can think of `postTask()` as a lower level API — it might be the right choice in specific scenarios. Library owners might be interested in exploring the nuanced differences between the two. For most cases, `main-thread-scheduling` provides a `scheduleTask()` method that mimics that API of `postTask()` while providing the extra benefits of the library.