FlutterRxBus icon indicating copy to clipboard operation
FlutterRxBus copied to clipboard

Concurrent modification during iteration

Open applecyg opened this issue 6 years ago • 2 comments

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); }); }

applecyg avatar Apr 23 '19 13:04 applecyg

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

appdev avatar Apr 24 '19 01:04 appdev

好的,非常感谢您的共享!谢谢!

在 2019年4月24日,上午9:36,appdev <[email protected]mailto:[email protected]> 写道:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/appdev/FlutterRxBus/issues/1#issuecomment-486033556, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AADHA2VPNPAMXVCNKWKML63PR62STANCNFSM4HHYADIA.

applecyg avatar Apr 24 '19 01:04 applecyg