w3c / FileAPI

File API
https://w3c.github.io/FileAPI/
Other
104 stars 44 forks source link

Race condition in Introduction example #48

Closed Qowyn closed 8 years ago

Qowyn commented 8 years ago

The example in the introduction attaches event handlers after calling readAsText which might lead to anything from missed progress events to missing all events.

See github/fetch#353

mkruisselbrink commented 8 years ago

The example should not have any race conditions. The actual spec for the readAsText operation (and all the other read operations) queues tasks for all the various conditions that could trigger events. So a spec-compliant implementation should never fire these events until after the event loop has processed tasks (which won't happen until all synchronous code has finished running, micro tasks have processed, etc).

Qowyn commented 8 years ago

Thanks for clearing that up, just read about how the event loop works. Now it seems to me that it should be nearly impossible to create a race condition in JS. Still looks a bit weird for someone like me without a strong JS background.