Skip to content

Fix #237 and #256: handle subscription errors #264

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

Merged
merged 4 commits into from
Sep 23, 2020

Conversation

zolkis
Copy link
Contributor

@zolkis zolkis commented Sep 14, 2020

Signed-off-by: Zoltan Kis [email protected]


Preview | Diff

@zolkis
Copy link
Contributor Author

zolkis commented Sep 14, 2020

Notes:

  • Added Subscription interface
  • the stop() method name was selected to be aligned with start() and stop() from similar interfaces (e.g. in Generic Sensors)
  • also, the name stop() makes it possible to add a start() method if we want to support temporary stop/start functionality for subscriptions.

Now since stop() replaces unsubscribeEvent() and unobserveProperty(), it has to inherit passing InteractionOptions and needs to return a Promise.

@zolkis
Copy link
Contributor Author

zolkis commented Sep 15, 2020

Also, factored out the selecting the unsubscribe Form for a given subscribe Form, which is marked non-normative.
Help is welcome on improving it.

Copy link
Member

@relu91 relu91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zolkis. I left some comments they are not really changes but suggestions. Feel free to ignore them .

On the other hand, now that I am seeing this new API defined I think we are trying too hard to merge two different API styles. The Subscription objects feels like EventTarget but it is not, since the event callbacks are passed to subscribeEvent/observeEvent method. On the other hand, we'd like to have a promise style for starting/stopping the underlying process. I know that I voted for this style, but it does not feel right. Futhermore, this paragraph from Web Platform Design Principles struck me:

For recurring events, it could be convenient to create a custom pair of APIs to "register"/"unregister", "subscribe"/"unsubscribe", etc., 
that take a callback and get invoked multiple times until paired cancel API is called.

Instead, use the existing event registration pattern and separate API controls to start/stop the underlying process (since event listeners should not have side-effects).

Since you are already suggesting that in the future we might add also the startmethod, we could go directly with an API similar to GenericSensor API. This means, that Subscription has the start method and the subscribeEvent/observeProperty will not return a Promise. What do you think?

index.html Outdated
If the underlying platform receives further notifications for this subscription with new <a>Property</a> value, implementations SHOULD
silently suppress them.
Whenever the underlying platform receives an error notification for
this subscription with an |error:Error|, run the following sub-steps:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rephrase a little bit:

Whenever the underlying platform receives an error notification or detects other errors (i.e. connection errors) for this subscriptions...

Mentioning only notifications it seems that the errors are only generated at the application level (also the unrecoverable). Even if later on the steps explains what to do with unrecoverable error, the source of this errors is not clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just say

Whenever the underlying platform detects errors (i.e. connection errors) for this subscription

</li>
<li>
If |subscription|'s [[\form]] is failure, reject |promise| with a
{{SyntaxError}} and abort these steps.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a fair algorithm, even if we really need a change in TD spec. Meanwhile, I think we can get away with the note, and this solution.

We can improve it a little bit if instead of having a result array, we just record the maximum scored form, and if we find someone with higher score update the variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since it is specifically informative, implementations are free to use a different algorithm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the array, it permits a single pass over an unordered set. Keep in mind that contributions for match level could come from different sources. While this algorithm could be optimized in that regard, I deliberately kept it this way to draw attention to this aspect (order of Forms should not affect the outcome of the search). Implementations could choose their algorithm anyway.

Also, feel free to propose an alternative algorithm, there probably is a better one, this was just a quick one.

@danielpeintner
Copy link
Contributor

On the other hand, now that I am seeing this new API defined I think we are trying too hard to merge two different API styles. The Subscription objects feels like EventTarget but it is not, since the event callbacks are passed to subscribeEvent/observeEvent method. On the other hand, we'd like to have a promise style for starting/stopping the underlying process. I know that I voted for this style, but it does not feel right. Futhermore, this paragraph from Web Platform Design Principles struck me:

@relu91 can you sketch the WebIDL how you would like to see it so that we have a better idea how it might look like... thanks!

@zolkis
Copy link
Contributor Author

zolkis commented Sep 23, 2020

On the other hand, now that I am seeing this new API defined I think we are trying too hard to merge two different API styles. The Subscription objects feels like EventTarget but it is not, since the event callbacks are passed to subscribeEvent/observeEvent method. On the other hand, we'd like to have a promise style for starting/stopping the underlying process. I know that I voted for this style, but it does not feel right.

I think there are legitimate uses of a subscribe mechanism, see for instance the Cookie Store API which uses both events and subscribe (with Promise).

I have evaluated the option with returning the Subscription object that has a start() method, in 2 scenarios:

  • with Promise, and start() is invoked automatically by subscribe()
  • without Promise, one should explicitly start() the subscription.

However, the latter doesn't play well with the semantics of a subscribe() function.

So either I would leave it as it is now, or include a start() method, but let the subscribe() invoke it, returning start()'s Promise.
But it's a complication, since start() should be void if we follow the Generic Sensor design (but that one has events so it's fine its start() is void). In our case, start() would need to return a Promise.

So in the end I think this proposal is the minimal one.

Copy link
Contributor

@danielpeintner danielpeintner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with the current WebIDL changes.

More/other improvements can come later...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants