-
Notifications
You must be signed in to change notification settings - Fork 53
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
Advanced handlers support, timeout #405
base: main
Are you sure you want to change the base?
Advanced handlers support, timeout #405
Conversation
-- ensure the handler hasn't timed out yet | ||
if o.timeout then | ||
-- remove handler if it timed out | ||
if (o.timeout.type == 'milliseconds' and o.timeout.value < msg.Timestamp) or (o.timeout.type == 'blocks' and o.timeout.value < msg["Block-Height"]) then |
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 think the having the handler still run at the deadline and only get removed after is the most straightforward implementation/solution, but I'm happy to change it to:
if (o.timeout.type == 'milliseconds' and o.timeout.value <= msg.Timestamp) or (o.timeout.type == 'blocks' and o.timeout.value <= msg["Block-Height"]) then
…r is not found by name
A note: adding an |
This prevents firing the event twice
I found myself coming across many scenarios, when I need multiple features for a single handler and I need to implement that every time separately. This aims to solve the problem, while being 100% backwards compatible.
What this PR adds:
This is great in situations, when you want to limit how long your handler can be used not with the times it can run, but with a deadline. After starting to work on this feature, I've found that this is something you want to implement as well in feat(handlers): refactor to include the ability to set a timeout #360
This basically makes sure that the process can handle errors with more freedom. For example, it allows developers to refund users, if an error is thrown in the handler. This allows them to use functions, such as
assert()
in the handler function, instead of having to do something like this, every time an error is thrown:errorHandler
featurerunType
overwritesThis allows the developer to overwrite the result of the pattern, if the pattern matches (continue or break). Also useful when the doesn't define the pattern with a function
Handlers.setActive(name, status)
)onRemove(reason)
hook for handlers to listen to handler removalsWhat I've changed:
Handlers.advanced(config)
)Handlers.append()
toHandlers.add()
I've found that these two functions are basically the same. Please let me know if I need to change this back.
Here is the schema used by the new
Handlers.advanced()
function'sconfig
param:Disclaimer about the
errorHandler
Since the
errorHandler
works by catching errors and not forwarding them to ao, the behavior of the handler changes when it is included. In my opinion, this disclaimer should be included in any documentation about the feature.For instance, normally in cases like the one below, the global value
SomeGlobal
will not change totrue
, because the error "invalidates" the entire execution, so no state updates are made:When the
errorHandler
is defined, the error will not invalidate the execution, it'll only be forwarded to theerrorHandler
, soSomeGlobal
will change totrue
, even tho an error is thrown after:Two things can be done, to avoid this: