-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dropping the `experimental_` prefix since this feature was confirmed working. Since the timer worker (introduced in #1557) is not going to be updated too often, we can skip an additional built step and just check in the prebuilt worker. The "source" file `worker.ts` and the script to generate worker are still there, but they are not used during build.
- Loading branch information
1 parent
cb2f218
commit 94dacef
Showing
5 changed files
with
30 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
// Do not modify this file manually. You can edit worker.ts if necessary | ||
// Do not modify this file manually. Instead, edit worker.ts | ||
// and the run ./generate-timer-worker.sh | ||
export const timerWorker = { | ||
get src(): string { | ||
throw new Error( | ||
'Timer worker source missing. Did you forget to run generate-timer-worker.sh?', | ||
); | ||
}, | ||
src: `const timerIdMapping = new Map(); | ||
self.addEventListener('message', (event) => { | ||
const request = event.data; | ||
switch (request.type) { | ||
case 'setTimeout': | ||
case 'setInterval': | ||
timerIdMapping.set(request.id, (request.type === 'setTimeout' ? setTimeout : setInterval)(() => { | ||
tick(request.id); | ||
if (request.type === 'setTimeout') { | ||
timerIdMapping.delete(request.id); | ||
} | ||
}, request.timeout)); | ||
break; | ||
case 'clearTimeout': | ||
case 'clearInterval': | ||
(request.type === 'clearTimeout' ? clearTimeout : clearInterval)(timerIdMapping.get(request.id)); | ||
timerIdMapping.delete(request.id); | ||
break; | ||
} | ||
}); | ||
function tick(id) { | ||
const message = { type: 'tick', id }; | ||
self.postMessage(message); | ||
}`, | ||
}; |