Skip to content

CounterThing example on main page does not work because observeProperty cannot keep up #1503

@jspaith

Description

@jspaith

I copy/pasted the 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.

// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    binding-httpIssues related to http protocol bindingbugSomething isn't workinggood first issueGood for newcomers

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions