UNPKG

872 BJavaScriptView Raw
1"use strict";
2
3// Copyright 2017-2018 Jaco Greeff
4// This software may be modified and distributed under the terms
5// of the ISC license. See the LICENSE file for details.
6module.exports = function onMessageResult(self, response) {
7 self.l.debug(() => ['handling: response =', response, 'id =', response.id]);
8 const handler = self.handlers[response.id];
9
10 if (!handler) {
11 self.l.error(`Unable to find handler for id=${response.id}`);
12 return;
13 }
14
15 try {
16 const subscription = self.handlers[response.id].subscription;
17 const result = self.coder.decodeResponse(response);
18
19 if (subscription) {
20 // flowlint-next-line unclear-type:off
21 self.subscriptions[result] = {
22 callback: subscription
23 };
24 }
25
26 handler.callback(null, result);
27 } catch (error) {
28 handler.callback(error);
29 }
30
31 delete self.handlers[response.id];
32};
\No newline at end of file