On Mar 18, 2006, at 4:18, Leopold Toetsch wrote:
On Mar 18, 2006, at 5:05, Allison Randal wrote:

  +=head3 Hybrid solution
  +
+Another option is to return a status object from each I/O operation.

I'm in favour of such a solution.

Also my favorite.

+The disadvantage is that a status object involves more overhead than a
  +simple integer status code.

Well, IO goes usually through several layers aka function calls, and isn't one of the fast operations a computer performs. And: - int status codes (if checked) are usually just converted to PMCs by HLL compilers - if PMC creation becomes a bottleneck, then we should fix it and not avoid or work around it

I had to list *some* kind of disadvantage, or it would sound too good to be true. ;)

Seriously, though, it's important to consider all the advantages and disadvantages, even if we decide the advantages outweigh the disadvantages (as is the case here).

That said I can imagine to unify sync/async at the surface. E.g.

sync operation:

  PResult = Pio."read"(n)    # PResult = String/IOError object

async operation:

  PAsync = new .IOAsync, Pcallback
  PAsync."set_callback"(Pcb)   # or method
  ...
  Pio."async"(PAsync)
  PStatus = Pio."read"(n)

Both the sync and async read bubble down the layers until one is found that supports the operation either directly or by e.g. emulating async. But due to the same function call signature, we can avoid duplication of code paths.

That interface is unnecessarily complex. But more importantly, the choice between async and sync is not set per filehandle, it's per operation. It could be very common to combine the two, such as using synchronous operations for opening and closing a filehandle, and only using asynchronous operations for the heavy lifting of slurping in an entire file.

But, yes, I agree with the principle of not maintaining two completely separate implementations for synchronous and asynchronous ops. The earlier design approached that by having the synchronous ops be asynchronous internally, but my draft suggests this be handled by having the asynchronous ops use the synchronous ops internally.

Allison

Reply via email to