janet icon indicating copy to clipboard operation
janet copied to clipboard

Janet streams and abstract types.

Open zevv opened this issue 1 year ago • 3 comments

Is there any official consensus and/or documentation on the implementation and use of abstract/OO types for streams in Janet?

  • What methods is a stream required to implement to be considered a "stream"? For example, ev/ streams seem to offer the :close, :read, :chunk and :write methods, but net/ has a bunch more (:flush, :accept, etc)
  • Is networking (library) code that builds on streams encouraged to use abstract method calls instead of calling net/... or ev/... functions directly? For example, Spork's HTTP code at this time depends directly on ev/... functions, which makes it hard (impossible) to re-use this code when running on my own stream types.

zevv avatar May 24 '23 05:05 zevv

I don't know of a consensus or docs.

Assuming there aren't issues for drafting something along these lines, may be some of the above text is a good start :)

sogaiu avatar May 24 '23 10:05 sogaiu

:close, :read;, :chunk, and :write are certainly what I would want to implement. If you use these methods, really are just using duck-typing for the streams, which is fine but you may want more. For example, :flush might make sense here but :accept probably does not.

bakpakin avatar May 24 '23 12:05 bakpakin

I think it would be helpful to define and document the mandatory set required to implement a stream so producers know what to offer, and consumers know what is safe to call without run time errors.

zevv avatar May 24 '23 12:05 zevv