- Notifications
You must be signed in to change notification settings - Fork40
Description
Theterminate method only has an effect on a presentation connection whose state isconnected.
I think a common scenario for callingterminate is when the controlling browsing context is about to disappear or when the user clicks on a button, to clean things up, regardless of the current application state.
This is what we try to do in the test suite for instance, so that subsequent tests start from a clean "no on-going presentation" state. However, sinceterminate only works onconnected presentations, terminating a presentation no matter what turns out to be more complex that simply callingterminate, leading to code such as:
// Try to terminate the presentationconnection.terminate();// If state was "connecting", previous call did nothing,// wait for the "connect" eventconnection.onconnect=()=>{connection.terminate();};// If state was "closed", we need to reconnect first. This will return a// presentation in "connecting" state. Previous event handler will eventually// take care of it if it's the same "connection", but it may not be.if(connection.state==='closed'){request.reconnect(connection.id).then(c=>{c.onconnect=()=>{c.terminate();};});}
I'm wondering whether the user agent could take care of some of that complexity, ideally so that developers can end up with a simpleconnection.terminate() call. This would require relaxing theterminate algorithm so that:
- It also applies to connections in the
connectingstate. The user agent would wait for the underlying connection to becomeconnected. - It also applies to connections in the
closedstate. The user agent would attempt to reconnect the underlying connection before it terminates it.
The latter change may be more problematic, and it seems reasonable to expect applications to deal with connections in theclosed state themselves. The former change seems easier and useful. If both changes are in place, developers can just issue a call toconnection.terminate() and be done with it. If only the former change is in place, developers would have to write something like:
if(connection.state==='closed'){request.reconnect(connection.id).then(c=>{c.terminate();});}else{connection.terminate();}
... which seems acceptable.