← 返回 openai 的题目列表Implement an Async Message Bus for sendAsyncMessage (Simulation)
类型:online_judge
Implement sendAsyncMessage and an End-to-End Simulation
Previously, sendAsyncMessage(nodeId, message) was assumed to be provided. Now implement a runnable single-machine simulation.
Tasks
Implement a simplified async messaging system sendAsyncMessage(nodeId, message):
Allow registering many nodes' receiveMessage callbacks.
Delivery must be asynchronous (e.g., enqueue then dispatch later via an event loop or thread pool).
Use the simulation to run the full workflow of either node counting or topology reconstruction.
Write test cases for:
Correctness.
Concurrency (multiple requests in flight).
Retries/duplicate deliveries (optional bonus): dedup still yields correct results.
Constraints
You may use language-native concurrency primitives, but you must not bypass messaging by directly reading global tree structure (tree knowledge stays inside node objects).
Clearly define the dispatch/queue model.
Example
Input
Build bus + nodes for edges: 1->[]; run count(1)
Output
1