Skip to content

修复mdImgReplace中的异步错误问题#103

Merged
liuyueyi merged 2 commits intoitwanger:mainfrom
EvenTiming:main
Feb 18, 2025
Merged

修复mdImgReplace中的异步错误问题#103
liuyueyi merged 2 commits intoitwanger:mainfrom
EvenTiming:main

Conversation

@EvenTiming
Copy link
Copy Markdown
Contributor

在原本的代码中,异步计算图像新路径并没有等待任务完成,而是直接进行下一步操作,导致imgReplaceMap其实为空。
加入等待异步完成语句前测试结果:
0f9eeda1e705f4540f03804dbc8e5f5
加入等待异步完成语句后测试结果:
d099096296ddb4dc0a5ffde71e90e1b

Copy link
Copy Markdown
Collaborator

@liuyueyi liuyueyi left a comment

Choose a reason for hiding this comment

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

这个地方不是问题哈,借助的是Closeable接口的try finally机制

}, img.getUrl());
}
// 等待所有图片转存完成
bridge.allExecuted();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

image
image

这个 try 语法,会在close方法中自动执行 allExecuted 方法; 关于 AsyncUtil的异步工具类的封装方法的实现全流程,可以参照系列博文:- trace-watch-dog | 一灰灰的站点

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

image
有问题的地方在初始化这里,markOver 的初始值应该是 false 而不是 true,期待你的更正

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

原来如此,又学到东西了

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已经修改

@liuyueyi liuyueyi merged commit 6459138 into itwanger:main Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants