LiveSplit.Server is not guaranteed to respond to messages in the same order they are received. This change uses the "nonce" field in the new JSON messaging standard to provide a unique identifier against which to match incoming and outgoing messages.
Currently, the class member this._openRequests added by this change is not actually used for anything. But it does provide a useful method for investigating errors or commands that never receive a response.
It also may be desired in the future to change the listening behavior of this library to use a single listener that looks up the appropriate Promise resolver in this._openRequests instead of the current behavior -- subscribing a new listener for every message. Another alternative would be to extend EventEmitter2 instead of EventEmitter, which would allow for namespacing events and subscribing listeners to only events emitted with their nonce. But as this would create a new dependency and be a larger change, I felt it made more sense to make the simpler change first.
LiveSplit.Server is not guaranteed to respond to messages in the same order they are received. This change uses the "nonce" field in the new JSON messaging standard to provide a unique identifier against which to match incoming and outgoing messages.
Currently, the class member
this._openRequests
added by this change is not actually used for anything. But it does provide a useful method for investigating errors or commands that never receive a response.It also may be desired in the future to change the listening behavior of this library to use a single listener that looks up the appropriate Promise resolver in
this._openRequests
instead of the current behavior -- subscribing a new listener for every message. Another alternative would be to extendEventEmitter2
instead ofEventEmitter
, which would allow for namespacing events and subscribing listeners to only events emitted with their nonce. But as this would create a new dependency and be a larger change, I felt it made more sense to make the simpler change first.Note that this PR depends on #6.