Skip to content

Commit

Permalink
Merge pull request #361 from martonlederer/feat/advanced-continue
Browse files Browse the repository at this point in the history
Support pattern specs in `Handlers.utils.continue()`
  • Loading branch information
twilson63 authored Oct 17, 2024
2 parents c883591 + 9ea2666 commit bcf99b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions process/handlers-utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ function _utils.reply(input)
end
end

function _utils.continue(fn)
assert(type(fn) == 'function', 'invalid arguments: (fn : function)')
function _utils.continue(pattern)
return function (msg)
local patternResult = fn(msg)
local match = _.matchesSpec(msg, pattern)

if not patternResult or patternResult == 0 or patternResult == "skip" then
return patternResult
if not match or match == 0 or match == "skip" then
return match
end
return 1
end
Expand Down
6 changes: 3 additions & 3 deletions process/handlers-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ Sends a reply to the sender of a message. The reply can be a simple string or a

- **Returns:** Function that takes a message object and sends the specified reply.

### continue(fn)
Inverts the provided pattern matching function's result if it matches, so that it continues execution with the next matching handler.
### continue(pattern)
Inverts the provided pattern's result if it matches, so that it continues execution with the next matching handler.

- **Parameters:**
- `fn` (function): Pattern matching function that returns `"skip"`, `false` or `0` if it does not match.
- `pattern` (function|table): Pattern to match

- **Returns:** Function that executes the pattern matching function and returns `1` (continue), so that the execution of handlers continues.

Expand Down

0 comments on commit bcf99b5

Please sign in to comment.