mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-18 07:03:01 -04:00
feat: handle python input synchronously (#52526)
Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
This commit is contained in:
committed by
GitHub
parent
8e457e7789
commit
583745e6ca
23
client/static/python-input-sw.js
Normal file
23
client/static/python-input-sw.js
Normal file
@@ -0,0 +1,23 @@
|
||||
self.addEventListener('install', function() {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', function() {
|
||||
self.clients.claim();
|
||||
})
|
||||
|
||||
let resolver;
|
||||
|
||||
self.onmessage = function(event) {
|
||||
resolver(event.data);
|
||||
}
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
const url = new URL(event.request.url);
|
||||
if (url.pathname === '/python/intercept-input/') {
|
||||
const response = new Promise((resolve) => {
|
||||
resolver = (data) => resolve(new Response(data));
|
||||
});
|
||||
event.respondWith(response);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user