提交 0112fd31 编写于 作者: M Matt Bierner

Delete cached service worker entries after a short timeout

上级 338b466e
......@@ -7,6 +7,8 @@
*/
const resourceRoot = '/vscode-resource';
const resolveTimeout = 30000;
/**
* @template T
* @typedef {{
......@@ -36,6 +38,7 @@ class RequestStore {
/**
* @param {string} webviewId
* @param {string} path
* @returns {Promise<T>}
*/
create(webviewId, path) {
const existing = this.get(webviewId, path);
......@@ -44,7 +47,17 @@ class RequestStore {
}
let resolve;
const promise = new Promise(r => resolve = r);
this.map.set(this._key(webviewId, path), { resolve, promise });
const entry = { resolve, promise };
this.map.set(this._key(webviewId, path), entry);
const dispose = () => {
clearTimeout(timeout);
const existing = this.get(webviewId, path);
if (existing === entry) {
return this.map.delete(this._key(webviewId, path));
}
};
const timeout = setTimeout(dispose, resolveTimeout);
return promise;
}
......@@ -91,7 +104,6 @@ const notFoundResponse = new Response('Not Found', {
status: 404,
});
self.addEventListener('message', (event) => {
switch (event.data.channel) {
case 'did-load-resource':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册