dispatcher: support enqueueing the same event type from listeners - close #1303

This commit is contained in:
skypjack
2026-01-22 17:19:16 +01:00
parent 7b456b9044
commit beda424de1
2 changed files with 22 additions and 5 deletions

View File

@@ -184,6 +184,24 @@ TEST(Dispatcher, NamedQueue) {
ASSERT_EQ(receiver.cnt, 3);
}
TEST(Dispatcher, AutoQueue) {
entt::dispatcher dispatcher{};
// enqueueing the same event type does not invalidate references - see #1303
dispatcher.sink<int>().connect<+[](entt::dispatcher &owner, int &value) {
for(int next{}; next < value; ++next) { owner.enqueue<int>(value); }
}>(dispatcher);
dispatcher.enqueue<int>(4);
dispatcher.update<int>();
ASSERT_EQ(dispatcher.size<int>(), 4u);
dispatcher.update<int>();
ASSERT_EQ(dispatcher.size<int>(), 16u);
}
TEST(Dispatcher, CustomAllocator) {
const std::allocator<void> allocator{};
entt::dispatcher dispatcher{allocator};