Commit 24c8236c authored by martin hou's avatar martin hou

fix: 文件列表查询增加超时返回处理

parent 90a6a8a0
......@@ -213,7 +213,7 @@ export function Home() {
return (
<>
<div style={{ display: 'flex', flexDirection: 'row', gap: '16px', padding: '16px', alignItems: 'center', flexWrap: 'wrap' }}>
<button onClick={connectx}>连接</button>
<button onClick={connect}>连接</button>
<button onClick={getFilePart}>获取文件</button>
<button onClick={writeSN}>SN写号</button>
<button onClick={getTime}>获取时间</button>
......
......@@ -322,6 +322,10 @@ function Jensen(log, conn) {
});
};
this._trigger = function(resp, msgid) {
trigger(resp, msgid);
}
const trigger = function (resp, msgid) {
if (current == null) return;
Logger.debug('jensen', 'trigger', pid + ':trigger - ' + current.substring(0, current.lastIndexOf('-')) + ' <---> cmd-' + (msgid || 'err'));
......@@ -764,13 +768,37 @@ Jensen.prototype.listFiles = async function () {
if (fcount == -1) {
// return [];
}
// 理论上,应该不要等太久,如果已经接近总量,但是等待的时间有点长,可以考虑提前退出了
//
// 如果已经等待过长的时间了,那就直接返回好了
let kv = tag + '-timer';
let now = new Date().getTime();
if (kv in jensen)
{
window.clearTimeout(jensen[kv]);
}
jensen[kv] = now;
if ((fc && files.length >= fc.count) || (fcount > -1 && files.length >= fcount)) {
// delete jensen[tag];
jensen[tag] = null;
window.clearTimeout(jensen[kv]);
console.log('jensen', 'list-files', 'normal return');
return files.filter((f) => {
return Boolean(f.time);
});
}
else
{
// 要怎么样触发这个回调?
jensen[kv] = window.setTimeout(() => {
jensen[tag] = null;
jensen._trigger(files.filter((f) => { return Boolean(f.time); }), QUERY_FILE_LIST);
console.log('jensen', 'list-files', 'timed return');
}, 1000);
}
});
return this.send(new Command(QUERY_FILE_LIST));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment