Re: File API proposal - marrying two alternatives

On Oct 6, 2009, at 10:07 PM, Jonas Sicking wrote:

>> [...]
>>
>>>
>>> Jonas' API:
>> // Don't forget var.
>>> reader = new FileReader;
>>> reader.readAsBinaryString(myFile);
>>
>> // What happens when we start a second read?
>> reader.readAsText(myFile);
>> // Race is on.
>>> reader.onload = handler;
>>> function handler(event) {
>>>  doStuffWith(event.target.response);
>>> }
>>>
>>
>> What is the order of expected outcome with multiple reads, as above?
>
> The second read cancels the first one. So after the readAsText call
> returns you'll only get events fired regarding that second load.


You might be confusing reponseXML and responseText mechanisms with  
send(). You can read either at different rates and it doesn't cause  
any problems. Also, attributes will behave differently than methods,  
and programmers factor that in their design.

To be sure, XHR does not allow *multiple* send() calls on an object.  
Step 2 of the send() method in 4.6.3 [1] checks if the send() method  
has already been called on the object. If so, an INVALID_STATE_ERR  
exception is raised and send() method is terminated. In effect, the  
second read fails.

Nikunj
http://o-micron.blogspot.com

[1] http://www.w3.org/TR/2009/WD-XMLHttpRequest-20090820/

Received on Wednesday, 7 October 2009 15:32:25 UTC