fix a bug that could cause "Helium.dispatch" to panic #552
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
sync.Map里的Range方法有个小坑:如果range的过程中有store / delete发生,range里不保证读到的是最终的状态。(这一点其实官方文档里也有说明)
calcium调用Helium.Unsubscribe之后直接就关闭了chan,此时dispatch仍然可能会读到这个chan,导致
panic: send on closed channel
。有两种办法可以避免这个问题,并且都不会对功能产生影响:1. 加个recover 2. 用RWMutex。这里采用了改动较小的第一种办法。