refactor(infra): remove setimmediate (#7975)

This commit is contained in:
EYHN
2024-08-26 11:57:24 +00:00
parent 611925fa10
commit 9ea4aaaf37
6 changed files with 14 additions and 12 deletions

View File

@@ -122,9 +122,10 @@ export class ComponentCachePool {
try { try {
i[Symbol.dispose](); i[Symbol.dispose]();
} catch (err) { } catch (err) {
setImmediate(() => { // make a uncaught exception
setTimeout(() => {
throw err; throw err;
}); }, 0);
} }
} }
} }

View File

@@ -93,21 +93,24 @@ export function effect(...args: any[]) {
const subscription = subject$.pipe.apply(subject$, args as any).subscribe({ const subscription = subject$.pipe.apply(subject$, args as any).subscribe({
next(value) { next(value) {
const error = new EffectError('should not emit value', value); const error = new EffectError('should not emit value', value);
setImmediate(() => { // make a uncaught exception
setTimeout(() => {
throw error; throw error;
}); }, 0);
}, },
complete() { complete() {
const error = new EffectError('effect unexpected complete'); const error = new EffectError('effect unexpected complete');
setImmediate(() => { // make a uncaught exception
setTimeout(() => {
throw error; throw error;
}); }, 0);
}, },
error(error) { error(error) {
const effectError = new EffectError('effect uncaught error', error); const effectError = new EffectError('effect uncaught error', error);
setImmediate(() => { // make a uncaught exception
setTimeout(() => {
throw effectError; throw effectError;
}); }, 0);
}, },
}); });

View File

@@ -458,7 +458,8 @@ export class LiveData<T = unknown>
const subscription = this.subscribe(v => { const subscription = this.subscribe(v => {
if (predicate(v)) { if (predicate(v)) {
resolve(v as any); resolve(v as any);
setImmediate(() => { // eslint-disable-next-line @typescript-eslint/no-floating-promises
Promise.resolve().then(() => {
subscription.unsubscribe(); subscription.unsubscribe();
}); });
} }

View File

@@ -1,4 +1,3 @@
import 'setimmediate';
import '@affine/component/theme/global.css'; import '@affine/component/theme/global.css';
import '@affine/component/theme/theme.css'; import '@affine/component/theme/theme.css';
import '@affine/core/bootstrap/preload'; import '@affine/core/bootstrap/preload';

View File

@@ -1 +0,0 @@
import 'setimmediate';

View File

@@ -1 +0,0 @@
import 'setimmediate';