add async
option to Hook
so setTimeout
in console methods can be disabled
#77
+101
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Because console-feed runs console methods in
setTimeout
, it cannot capture changes happening synchronously between logs. For instance,will log:
I believe this
setTimeout
was added for performance reasons. I'm sure that's preferable for some use-cases, but for other use-cases, it is confusing and certainly not ideal. (For example: processing/p5.js-web-editor#1203 (comment).)I believe this issue is the root cause of #23 & #66.
Possible solution
I don't know the details of the performance issues the
setTimeout
was added to mitigate. It's possible thesetTimeout
should simply be removed.If not, then it would be great if this behavior could be customizable. In this PR, I add a new option called
async
toHook
. By default,async
istrue
, reproducing the current behavior. But ifasync
is set tofalse
, thesetTimeout
is replaced with immediate execution of its contents.Hook
already has a single boolean argument to controlencode
. Having multiple boolean arguments results in less-readable code, so I replaced this with an options object. (For backwards-compatibility, a user can still just pass in a single boolean forencode
.)Please let me know what you think of this approach! I'd be happy to make changes depending on what you think is best.
Thanks a bunch!