Asynchronous File Writing
The asynchronous method of file writing puts a write request on the event queue and then returns control back to the calling code. The actual write does not take place until the event loop picks up the write request and executes it. You need to be careful when performing multiple asynchronous write requests on the same file because you cannot guarantee the execution order unless you wait for the first write callback before executing the next one. Typically the simplest way to do this is to nest writes inside the callback from the previous write. The code in Listing 6.3 illustrates this process.
To write to a file asynchronously, first open it using open() and then after the callback from the open request has executed, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access