@indra.ai/deva 1.64.45 → 1.64.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/_data/tests.json CHANGED
@@ -43,7 +43,7 @@
43
43
  "file": "05-messaging.test.js",
44
44
  "title": "Messaging",
45
45
  "describe": "question() runs local /commands and #ask calls to child Devas, child errors reach the asker right away, and missing or silent targets answer not found or timeout.",
46
- "count": 12
46
+ "count": 13
47
47
  },
48
48
  {
49
49
  "file": "06-shutdown.test.js",
package/index.js CHANGED
@@ -146,9 +146,12 @@ class Deva {
146
146
  try {
147
147
  this._bind.forEach(bind => { // loop over the bind items func, method, listener...
148
148
  if (this[bind]) for (let x in this[bind]) { // if the root has a bind func, method, listener
149
- if (typeof this[bind][x] === 'function') { // check to make sure object is a fucntion
149
+ // check to make sure the binding is a function.
150
+ if (typeof this[bind][x] === 'function') {
151
+ // check to make sure object is a function
150
152
  if (!this._binding.has(bind)) this._binding.set(bind, {});
151
- this[bind][x] = this[bind][x].bind(this); // bind the item from the bind object
153
+ this._binding.get(bind)[x] = this[bind][x].toString();
154
+ this[bind][x] = this[bind][x].bind(this);
152
155
  }
153
156
  }
154
157
  });
@@ -779,7 +782,7 @@ class Deva {
779
782
  if (this.events) {
780
783
  packet.a = false;
781
784
  this.ignore(evt, pending.handler);
782
- this.talk(evt, packet);
785
+ this.talk(evt, this.lib.copy(packet));
783
786
  }
784
787
  };
785
788
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "31711622713594414221",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.64.45",
4
+ "version": "1.64.48",
5
5
  "description": "Deva Core a Vedic-inspired Event Based Context Aware Feature, Zone, Action, and State Machine integrated Artificial Intelligence Framework",
6
6
  "main": "index.js",
7
7
  "license": "VLA:31711622713594414221 LICENSE.md",
@@ -119,4 +119,33 @@ test.describe('after init', () => {
119
119
  assert.equal(deva._pending.size, 0, 'timeout cleans up the pending ask');
120
120
  deva.events.removeListener('silent:ask', silent);
121
121
  });
122
- });
122
+
123
+ test('a late answer after the ask timeout is dropped and the caller keeps the timeout', async () => {
124
+ let late = false; // the packet the slow target answers with.
125
+ let closed = false; // the a:false close packet release() sends.
126
+ const slow = packet => {
127
+ const evt = `slow:ask:${packet.id.uid}`;
128
+ deva.events.once(evt, p => { closed = p; }); // catch the close packet.
129
+ setTimeout(() => {
130
+ late = {...packet, a: {text: 'too late'}};
131
+ deva.events.emit(evt, late);
132
+ }, 300); // answer after the 200ms ask timeout.
133
+ };
134
+ deva.events.on('slow:ask', slow);
135
+
136
+ let calls = 0;
137
+ const result = await deva.question('#slow shout hi').then(r => { calls++; return r; });
138
+ assert.equal(result, deva._messages.asktimeout);
139
+ assert.equal(deva._pending.size, 0, 'timeout cleans up the pending ask');
140
+
141
+ // the close packet is a copy marked a:false.
142
+ assert.equal(closed.a, false, 'release() sends a:false');
143
+
144
+ // wait past the late answer and check nothing picked it up.
145
+ await new Promise(r => setTimeout(r, 200));
146
+ assert.ok(late, 'the slow target did answer late');
147
+ assert.equal(calls, 1, 'the caller resolved exactly once');
148
+ assert.equal(deva.events.listenerCount(`slow:ask:${late.id.uid}`), 0, 'no listener left for the late answer');
149
+ deva.events.removeListener('slow:ask', slow);
150
+ });
151
+ });