eclipse-thingweb / eclipse-thingweb/node-wot
CounterThing example on main page does not work because observeProperty cannot keep up
- Dominant language
- TypeScript
- Stars
- 192
- Forks
- 100
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 6
Description
I copy/pasted the [examples](https://github.com/eclipse-thingweb/node-wot?tab=readme-ov-file#examples) on the welcome readme.md for the counter thing and client.
Repro
* Install various NPM packages
* Copy the snippets into `counterThing.js` and `counterClient.js`
* Run node on both of these in separate terminals
Behavior -- there are only two notifications fired and the client hangs forever
```
~/developer/jspaith/scratch/wot/test1 >node ./counterClient.js
count: 2
count: 4
```
This suggested a timing issue where the client isn't receiving updates and is hanging because its waiting for 5 before terminating. It seems that the `observeProperty` is not keeping up. Brute force, but this updated script does work.
I'm not doing a PR directly to the home page because I don't know if the script needs this paradigm or something is off with underlying `observeProperty`.
```javascript
// client.js
// Required steps to create a servient for a client
const { Servient } = require("@node-wot/core");
const { HttpClientFactory } = require("@node-wot/binding-http");
const servient = new Servient();
servient.addClientFactory(new HttpClientFactory(null));
servient.start().then(async (WoT) => {
const td = await WoT.requestThingDescription("http://localhost:8080/counter");
// Then from here on you can consume the thing
let thing = await WoT.consume(td);
// Read initial value
let read = await thing.readProperty("count");
console.log("initial count:", await read.value());
for (let i = 0; i < 5; i++) {
await thing.invokeAction("increment");
read = await thing.readProperty("count");
console.log("count:", await read.value());
}
// Clean shutdown
servient.shutdown();
}).catch((err) => { console.error(err); });
```
After this change client works fine
```
~/developer/jspaith/scratch/wot/test1 >node ./counterClient.js
initial count: 0
count: 1
count: 2
count: 3
count: 4
count: 5
~/developer/jspaith/scratch/wot/test1 >
```
Environment:
* WSLv2 / Ubuntu 22
* Windows 11 host
* Node version v18.20.8
* npm version 10.8.2
* I'm using the readme.md associated with #13ea375d323a93646b44bc79386b37703e53f598 in this repo.
Contributor guide
Assessment
This issue has not been assessed yet.