-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(chatView): Enhance chatView by avoiding webview destruction …
…and boosting operation speed (#70) * refactor(chatView): Enhance chatView by avoiding webview destruction and boosting operation speed * Optimize chatView request: Switch from loop waiting to waiting for chatView onLoad
- Loading branch information
Showing
6 changed files
with
77 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
interface Deferred<T> { | ||
abort: () => void; | ||
resolve: (value: T) => void; | ||
reject: (reason?: unknown) => void; | ||
promise: Promise<T>; | ||
} | ||
|
||
export function defer<T>(signal?: AbortSignal): Deferred<T> { | ||
const ac = new AbortController(); | ||
const dtd = {} as Deferred<T>; | ||
|
||
dtd.promise = new Promise((resolve, reject) => { | ||
dtd.resolve = resolve; | ||
dtd.reject = reject; | ||
}); | ||
|
||
function onDidAbort() { | ||
dtd.reject(new Error('user aborted')); | ||
} | ||
|
||
ac.signal.addEventListener('abort', onDidAbort); | ||
|
||
if (signal) { | ||
signal.addEventListener('abort', onDidAbort); | ||
} | ||
|
||
dtd.abort = function () { | ||
ac.abort(); | ||
}; | ||
|
||
return dtd; | ||
} |
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