janet
janet copied to clipboard
Janet streams and abstract types.
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, butnet/
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/...
orev/...
functions directly? For example, Spork's HTTP code at this time depends directly onev/...
functions, which makes it hard (impossible) to re-use this code when running on my own stream types.
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 :)
: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.
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.