Expand/Shrink

flush

Definition: flush(integer fn)
Description: When you write data to a file, Phix normally stores the data in a memory buffer until a large enough chunk of data has accumulated. This large chunk can then be written to disk very efficiently. Sometimes you may want to force, or flush, all data out immediately, even if the memory buffer is not full. To do this you can invoke flush(fn), where fn is the file number of a file open for writing or appending.
pwa/p2js: Not supported.
Comments: When a file is closed, all buffered data is automatically flushed out. There is absolutely no need to invoke flush() before invoking close(). When a program terminates, all open files are flushed and closed automatically.

Use flush() when another process may need to see all of the data written so far, but you are not ready to close the file yet.
Example:
f = open("logfile", "w")
puts(f, "Record#1\n")
puts(1, "Press Enter when ready\n")
flush(f)  -- This forces "Record #1" into "logfile" on disk.
          -- Without this, "logfile" will appear to have 
          -- 0 characters when we stop for keyboard input.
s = gets(0) -- wait for keyboard input
Implementation: via :%opFlush / fflush() in builtins\VM\pfileioN.e (an autoinclude) - be warned however it is low-level complicated stuff that you do not need to know.
See Also: close, lock_file