-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
be a well-behaved pull-stream #1
Comments
@dominictarr thanks for creating this issue would you say a step in the right direction would be to implement your above suggestion? rather still new to the
would something like a simple array buffer help in that situation ? |
yup. a stream of all the events would be correct. But might be unnecessary in some cases. This is currently the best document about exactly what is pull-stream behavior. We are working on smoothing the learning curve, so feedback, questions, etc are appreciated! |
i added a pr #2 not sure if that helps address the callback issue where it gets called twice... |
@dominictarr after reading a few times over the above spec link you shared i have a few questions: does the person implementing a source have to pass the data to the callback from read in a different callstack iow using some kind of scheduler like a simple nextTick? or what guarantees the asynchronicity of the source function? Edit is there a better place to ask these questions? |
you can call back async. but I'd recommend calling back sync if you got your data sync. that is what most i've done in all my pull-streams. It makes it a little bit more tricky, but it also makes it easier to test, because sync enables you to reason more precisely about what order events happen in. Also, nextTick actually adds quite a bit of overhead. pull-streams are often long chains of simple transforms, that they can be async but do not need to be is very valuable. |
@dominictarr that makes sense, the reason i asked was this quote from the spec
and when i was browsing the sources files i didnt see anything made me think it was also any thoughts on #2 ? thanks for all of the help 😄 |
by async function I mean just that it takes a Some people say that you should always call a function either always sync or always async, but I disagree here. pull-stream work well with functions that may either be async or sync. |
Isnt that because of zalgo? ... also callback doesnt seem to always mean |
yes. it has been called "zalgo". there are no formal definitions, but here are the distinctions that I make about uses of functions in node.
Always making "async functions" callback after a time is pretty good advice, but never say "never", never say "always". Using |
oh it just occured to me that you could call the function passed to map or reduce a functional function. It shouldn't have side effects, and that means not having any behavior after it's called (so no async) Normally, in my code when I have a functional function I name in I don't know if there is a type checker that checks this, but I feel that it would be very useful for writing asynchronous programs. (for the record, I don't object to runtime type errors, because they are pretty easy to fix. async timing bugs are way harder though) |
based on the fact that it shouldn't have a side-effect you could also call those functions passed to map/reduce a "pure function" i havent personally used Its more evident to the developer and then the maintainers when you know what the function is doing and explicitly returning. Obviously there are situations where you can not avoid side-effects especially when it comes to dealing with the browser and its quirks... and there are various nice functional approaches to dealing with isolating side-effects in a program. |
sure. there is still a time and place for side effects also it would be fine to have a lamba that is called async, like |
it would be pretty neat to have a language which could enforce this kinda thing. in my opinion it this would be more helpful than regular type checks. |
If the sink always reads synchronously, this module should work fine,
however in some situations it will behave in correctly.
https://github.com/davidchase/pull-dom-events/blob/master/index.js#L7
If an event happens more than once before the sink has read again, it will call the callback twice.
(but with a new value)
There are different ways you could address this, depending on what behavior you want with dom events, but the simplest thing would be to unset
callback
before calling it.then you know callback can never be called twice, even if it's called recursively (before itself has returned)
Another question is what do do about events that happen inbetween calls?
one idea would be to let them drop, so you could have a stream of mousemove events,
and whenever you call read you get either the most recent or the next mouse event.
If you just implement the above suggestion, you'll always get the next mouse event.
you could also keep the most recent event, and respond with that if it hasn't been read yet.
for keyboard events you might want to keep the sequence of events?
The text was updated successfully, but these errors were encountered: