-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP fix: issue https://github.com/eclipse/thingweb.node-wot/issues/230 ? #232
Conversation
remove resolve
Why does Travis not run the tests for this PR? |
Could it be also fixing #202 ? |
It seems to actually run but not display here. |
IMHO, the subscribe function should resolve if the subscription was successful. Any other error that happens after that moment, should be communicated to the subscriber through the listener interface. |
Agree with you @relu91 , but listener not notify about any error |
in fact (for http binding, mqtt), what I see is that the promise is resolved after the first event triggered, and it can failed if no event emited for 60 * 60 * 1000 seconds (one hour). |
One possible solution could be to change the WoTListener signature like the following: type WotListener = (data: any,error?:any) => void and in return client.subscribeResource(form,
(content) => {
if (!content.type) content.type = form.contentType;
try {
let value = ContentManager.contentToValue(content, <any>te.data);
listener(value);
} catch {
listener(null,new Error(`Received invalid content from Thing`));
}
},
(err) => {
listener(null,err);
},
() => {
resolve(); // I am not sure that we need to call resolve here...
}
);
} However, we probably need to make a more drastic change. From the specs the subscribe method should resolve when the underlying connection is established. Consequently, we might change the |
Correct, but this would require a change in the Scripting API (see https://w3c.github.io/wot-scripting-api/#idl-index) |
I am not really sure if there is a choice regarding this change in the Scripting API. I see two main problems with the current implementation/design:
The solution to both of this problems would be the proposed change to WotListener and is therefore required? |
Protocols differ from (JavaScript) programmatic interfaces in what concerns subscriptions vs error management. Usually event subscriptions (in SW) are for events (i.e. positive outcome): whenever the event is triggered, the subscribers are notified. The subscriber is interested in the events. Therefore, the Usually when errors occur, there are separate events for conveying those errors. Usually there is one If the Scripting API would mandate an event |
+1
That is also an option. However, traditionally (if one can speak of such in JS) errors are communicated via an error event, i.e. if the protocol signals error, the implementation fires the How can the app know where the error belongs? From the error content the implementation generates. We need to define an error for this in the Scripting API if we want to support the use case. |
I think that we can start by thinking of the following cases:
All these can be mapped to operations of Consumed Thing interface or Listener interface. It would be interesting to think if there can be other cases. |
I close this PR unmerged since the new API is coming also and makes the effort obsolete ... |
remove resolve