Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent modification during iteration #1

Open
applecyg opened this issue Apr 23, 2019 · 2 comments
Open

Concurrent modification during iteration #1

applecyg opened this issue Apr 23, 2019 · 2 comments

Comments

@applecyg
Copy link

static void destroy({tag}) {
_list.forEach((rxBus) {
if (tag != null && tag != _DEFAULT_IDENTIFIER && rxBus.tag == tag) {
rxBus.subject.close();
_list.remove(rxBus);
} else if ((tag == null || tag == _DEFAULT_IDENTIFIER) && rxBus.tag == _DEFAULT_IDENTIFIER) {
rxBus.subject.close();
_list.remove(rxBus);
}
});
}
在进行迭代循环时试图删除list中内容,导致异常抛出,建议的修改方案如:
///事件关闭
static void destroy({tag}) {
var toRemove = [];
_list.forEach((rxBus) {
if (tag != null && tag != _DEFAULT_IDENTIFIER && rxBus.tag == tag) {
rxBus.subject.close();
toRemove.add(rxBus);
} else if ((tag == null || tag == _DEFAULT_IDENTIFIER) &&
rxBus.tag == _DEFAULT_IDENTIFIER) {
rxBus.subject.close();
toRemove.add(rxBus);
}
});
toRemove.forEach((rxBus) {
_list.remove(rxBus);
});
}

@appdev
Copy link
Owner

appdev commented Apr 24, 2019

好的,稍后我测试完后会把这个更改提交上的

@applecyg
Copy link
Author

applecyg commented Apr 24, 2019 via email

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

No branches or pull requests

2 participants