Skip to content

Commit

Permalink
refactor(infra): remove setimmediate
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Aug 26, 2024
1 parent bc86f0a commit ba6fb1d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions packages/common/infra/src/framework/core/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ export class ComponentCachePool {
try {
i[Symbol.dispose]();
} catch (err) {
setImmediate(() => {
// make a uncaught exception
setTimeout(() => {
throw err;
});
}, 0);
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions packages/common/infra/src/livedata/effect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,24 @@ export function effect(...args: any[]) {
const subscription = subject$.pipe.apply(subject$, args as any).subscribe({
next(value) {
const error = new EffectError('should not emit value', value);
setImmediate(() => {
// make a uncaught exception
setTimeout(() => {
throw error;
});
}, 0);
},
complete() {
const error = new EffectError('effect unexpected complete');
setImmediate(() => {
// make a uncaught exception
setTimeout(() => {
throw error;
});
}, 0);
},
error(error) {
const effectError = new EffectError('effect uncaught error', error);
setImmediate(() => {
// make a uncaught exception
setTimeout(() => {
throw effectError;
});
}, 0);
},
});

Expand Down
3 changes: 2 additions & 1 deletion packages/common/infra/src/livedata/livedata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ export class LiveData<T = unknown>
const subscription = this.subscribe(v => {
if (predicate(v)) {
resolve(v as any);
setImmediate(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Promise.resolve().then(() => {
subscription.unsubscribe();
});
}
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/electron/renderer/shell/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'setimmediate';
import '@affine/component/theme/global.css';
import '@affine/component/theme/theme.css';
import '@affine/core/bootstrap/preload';
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/mobile/src/polyfill/set-immediate.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/frontend/web/src/polyfill/set-immediate.ts

This file was deleted.

0 comments on commit ba6fb1d

Please sign in to comment.