Re: [webrtc-pc] replaceTrack and removeTrack: Synchronous?

> setting the track after it was null, which would arguably lead to unexpected behavior, whether or not racy

Most async methods are spec'ed to modify JS state on success, so this doesn't seem unexpected to me, much like both of these produce the same result:
```js
let x;
Promise.resolve().then(() => x = 1);
x = 2;
```
```js
let x = 2;
Promise.resolve().then(() => x = 1);
```
Similarly, both of these produce the same result:
```js
sender = pc.addTrack(t1);
sender.replaceTrack(t2);
pc.removeTrack(sender);
```
```js
sender = pc.addTrack(t1);
pc.removeTrack(sender);
sender.replaceTrack(t2);
```
What may be unexpected is that `removeTrack` is just a glorified setter for `track` and `direction`.

In practice, I expect racing like this is usually a bug, and best avoided:
```js
sender = pc.addTrack(t1);
await sender.replaceTrack(t2);
pc.removeTrack(sender);
```

-- 
GitHub Notification of comment by jan-ivar
Please view or discuss this issue at https://github.com/w3c/webrtc-pc/issues/1677#issuecomment-349861201 using your GitHub account

Received on Thursday, 7 December 2017 04:41:11 UTC