Re: [web-animations] AnimationPlayer.ready confusion

Brian Birtles <bbirtles@mozilla.com> писал(а) в своём письме Tue, 10 Feb  
2015 06:55:32 +0600:

>> player.pause(); // => let's assume that player is immediately ready,
>> // so pending pause task is not scheduled, all necessary actions are
>> immediately executed
>
> Why is the player immediately ready? Are you assuming the player is  
> already paused?
>
> If so, I think we should abort the procedure early in that case. As far  
> as I can tell, the procedure doesn't currently do that but it probably  
> should. I'll add an issue for that.

The procedure to pause a player reads (  
http://w3c.github.io/web-animations/#pause-a-player ):
> ...
> 6. Schedule a task to be executed at the first possible momentafter the  
> user agent has performed any processing necessaryto suspend the playback  
> of player’s source content, if any.The task shall perform the following  
> steps:
> ...

I think, that meaning "Schedule a task" also allows to execute the task  
immediately.
I assume that some implementations might be ready to execute the task  
immediately,
because processing necessary to suspend the playback is not required or
can be competed immediately.



>> // player.ready promise is fulfilled
>>
>> player.ready.then(function() { // => because player.ready promise is
>> fulfilled,
>> // the function is executed immediately, 'paused' is displayed.
>>      alert(player.playState);
>> });
>>
>> player.play();
>> // executes 'play a player' procedure
>> // http://w3c.github.io/web-animations/#playing-a-player-section
>> // there is no pending task
>> // player.ready promise is replaced with new one, which has no handler
>
> In this case, the function associated with the ready promise is not run  
> immediately. Rather, it queues a microtask:
>
>    "A promise p is fulfilled if p.then(f, r) will immediately enqueue a  
> Job to call the function f."[1]
>
> As a result, the subsequent call to player.play() will happen *before*  
> the callback is run.

Unfortunately, I am not so good with the Promises spec.
But isn't possible for promise to execute the function immediately,
instead of scheduling a microtask?

>> 2. Methods play(), pause(), reverse() can replace AnimationPlayer.ready
>> with a new Promise object. There is no way to predict whether
>> AnimationPlayer.ready will be replaced or not, because it depends on
>> whether the player has pending tasks or not.
>
> You can tell if it will be replaced by checking if playState is  
> 'pending'. If playState is pending we will re-use the same Promise  
> object.
>
>
>> For example, how to get some function called in response to some method
>> call (pause() or play() or reverse())? I.e. I call, for example, method
>> pause() and would like to get my handlePause() function called exactly
>> when player pause operation is complete.
>
> What if that pause never completes because there is a call to play() in  
> the meantime?

I am sorry, my statement is inexact.
I would like to get my handlePause() function called when player
completes "any processing necessary to suspend the playback
of player’s source content, if any." I.e. it should be called
at the same moment the player.ready.then() would call it without
any subsequent play(), reverse(), etc calls.


>> Is it possible to change the specification, that each method
>> (play, pause, reverse, finish) return unique Promise object related
>> to the method. So the following promise-like code could be possible:
>>
>> player.pause().then(handlePause, rejected);
>> player.play().then(handlePlay, rejected);
>> player.finish().then(handleFinish, rejected);
>
> I prefer this but the main problem is just the naming of play(). What do  
> you think of using resume()?

resume() is a counterpart of pause().
But resume() does not look well for beginning of the playback.
I think start() as a counterpart to finish() would be better.
And I like the idea that play().then( ... ) would execute after the  
animation had finished.

Thanks,
Aleksei.

Received on Tuesday, 10 February 2015 07:04:29 UTC