Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hooks/useNotifyWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { FormStore } from './useForm';
/**
* Call action with delay in macro task.
*/
const macroTask = (fn: VoidFunction) => {
export const macroTask = (fn: VoidFunction) => {
const channel = new MessageChannel();
channel.port1.onmessage = fn;
channel.port2.postMessage(null);
Expand Down
7 changes: 5 additions & 2 deletions src/utils/delayUtil.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { macroTask } from '../hooks/useNotifyWatch';
import raf from '@rc-component/util/lib/raf';

export default async function delayFrame() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The async keyword is redundant here as the function body does not use await. Since you are explicitly creating and returning a Promise, you can remove async and add an explicit return type for better clarity and to avoid unnecessarily wrapping a promise in another promise.

Suggested change
export default async function delayFrame() {
export default function delayFrame(): Promise<void> {

return new Promise<void>(resolve => {
raf(() => {
resolve();
macroTask(() => {
raf(() => {
resolve();
});
});
});
}
Loading