mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-06-25 17:10:43 +00:00
wip
This commit is contained in:
parent
43f20e44c3
commit
fb130466ae
3 changed files with 26 additions and 3 deletions
|
|
@ -84,6 +84,7 @@ import { store } from '@/store.js';
|
|||
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
||||
import { PreviewEngineController } from '@/world/room/previewEngineController.js';
|
||||
import MkInput from '@/components/MkInput.vue';
|
||||
import { withTimeout } from '@/utility/promise-timeout.js';
|
||||
|
||||
// TODO: instanceのidと紛らわしいのでid -> typeにする
|
||||
|
||||
|
|
@ -168,8 +169,7 @@ watch(selectedId, (newId) => {
|
|||
const closeWaiting = os.waiting();
|
||||
nextTick(() => {
|
||||
try {
|
||||
// TODO: timeout
|
||||
controller.loadObject(newId).then(res => {
|
||||
withTimeout(controller.loadObject(newId), 10000).then(res => {
|
||||
selectedInstanceId.value = res.id;
|
||||
selectedObjectOptionsState.value = deepClone(res.options);
|
||||
controller.resumeRender();
|
||||
|
|
|
|||
23
packages/frontend/src/utility/promise-timeout.ts
Normal file
23
packages/frontend/src/utility/promise-timeout.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
|
||||
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||
// workerで実行される可能性がある
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
timeoutId = setTimeout(() => {
|
||||
reject(new Error('Operation timed out'));
|
||||
}, ms);
|
||||
});
|
||||
|
||||
return Promise.race([promise, timeoutPromise])
|
||||
.finally(() => {
|
||||
// workerで実行される可能性がある
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
clearTimeout(timeoutId);
|
||||
});
|
||||
}
|
||||
|
|
@ -292,7 +292,7 @@ export abstract class EngineControllerBase<T extends RoomEngineBase> {
|
|||
}
|
||||
}
|
||||
|
||||
protected callAndWaitReturn<FN extends keyof T>(fn: FN, args: Parameters<T[FN]> = [] as any): Promise<ReturnType<T[FN]>> {
|
||||
protected callAndWaitReturn<FN extends keyof T>(fn: FN, args: Parameters<T[FN]> = [] as any): ReturnType<T[FN]> extends Promise<any> ? ReturnType<T[FN]> : Promise<ReturnType<T[FN]>> {
|
||||
if (!this.isReady.value) {
|
||||
throw new Error('Engine is not initialized');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue