-
Notifications
You must be signed in to change notification settings - Fork 496
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
refactor(@embark/cmd-controller): re add cargo for file watcher #1855
Conversation
DeepCode Report (#5efe35)DeepCode analyzed this pull request. |
It's tricky to use RxJS for this task because it produces "push flows". However, if IxJS were used there wouldn't be a need for a manual throttle, as that lib's batch operation will give the desired behavior: https://gist.github.com/michaelsbradleyjr/271c3dabdabf68412e254d52b3934e62 |
I tried your gist with |
There could be something wrong with the gist as I coded it rather in the abstract. However, I tested that batch, etc. work as I understood them to work with some scripts that I have in another gist: https://gist.github.com/michaelsbradleyjr/62d16f63a3ac318b42d8132fc178acda#file-index-js There are 4 scripts in that gist (including a
In the case of the file watcher it seemed like we didn't actually care about the batched values, i.e. we filtered on the file type before consuming the observable with ix's from and batch, so that's why in the gist the |
Thinking about the throttle, I can see how the leading delay could be helpful, i.e. for more reliably getting one trigger versus two when there is a relatively big time gap between batches, e.g. between multi-save operations in an IDE. I'm thinking currently about how to put it between ixFrom and ixBatch or between the observable and ixFrom. |
See: #1855 (comment). I updated the gist to debounce the Rx pipes: https://gist.github.com/michaelsbradleyjr/271c3dabdabf68412e254d52b3934e62#file-filewatcherevents-js-L2-L4 Thinking through it in steps...
|
@michaelsbradleyjr thanks for looking into it. gets me to learn more. |
Thinking about it some more, in this situation it would also work just as well to use Rx's debounce; impl would be mostly the same but with the following additions/changes:
It doesn't really matter for this purpose whether the debounce is happening in the push or pull pipe, the effect will be the same. |
Yes, the results should be the same with Thinking in terms of pipes — push and pull — is, I believe, generally more powerful and provides for better composition than the patterns in the async library. (I may be wrong about that, of course). However, if you look at the docs site for async and then operators suites for Ix and Rx (just the names, I mean), it's clear that there is huge conceptual crossover: https://github.com/ReactiveX/IxJS/tree/master/src/asynciterable/pipe That is Rx and Ix (those two are complementary not either/or) and the async lib ultimately help a JS programmer accomplish the same things. Which approach is better and/or which is easier to understand? Personal preference probably plays a big role in answering that question. I found many of the async examples for the fancier functions hard to understand at first, while the Rx/Ix concepts became clear pretty quickly. Whatever you think is best, I'm totally onboard, just always like to look at a problem from different angles. |
For what it's worth, I experimented with debounce in the Rx pipe vs. in the Ix pipe and I found that debouncing the push pipe seems to work better: https://gist.github.com/michaelsbradleyjr/5abf097e9c2b99d101003d6c2cafb1ed With that script I get:
That's exactly what I expected. Now, if line 32 is commented and 34 is uncommented, so that the pull pipe is debounced instead of the push pipe, I get:
I was surprised by the difference — I thought it would be very similar. After running it several times, I find the output is consistent. Notice how I suspect it has to do with the characteristics of the async pull generally in relation to the timer (maybe microtask vs. macrotask race?); or there could be a subtle bug in Ix's I updated #1855 (comment). I also filed an issue on the Ix repo: ReactiveX/IxJS#282. |
(cherry picked from commit 5c77b40)
5c77b40
to
f75a7ee
Compare
if (tasks.includes('contract') || tasks.includes('config')) { | ||
try { | ||
await compileAndDeploySmartContracts(engine); | ||
return new Promise((resolve) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest instead of relying on outputDone
we specifically wait for await engine.events.request2('pipeline:generateAll'...)
, this way it's very explicity and we don't have to rely on an implicit event that might or might not be there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
I tried using RxJS, but I couldn't find a way to have a timeout like the one we have right now and as before. That timeout is useful to throttle instantaneous file changes, like using an IDE that enables to change and save multiple files at once. Without that throttle, it would start the pipeline for each file modified, but with it, it runs only once for all.