Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Add missing exit state to composer.try FSM #44

Merged
merged 1 commit into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function init(__eval__, composition) {
case 'try':
var body = compile(json.body, path + '.body')
const handler = chain(compile(json.handler, path + '.handler'), [{ type: 'pass', path }])
var fsm = [[{ type: 'try', path }], body].reduce(chain)
var fsm = [[{ type: 'try', path }], body, [{ type: 'exit', path }]].reduce(chain)
fsm[0].catch = fsm.length
fsm.slice(-1)[0].next = handler.length
fsm.push(...handler)
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,11 @@ describe('composer', function () {
.then(activation => assert.deepEqual(activation.response.result, { message: 'foo' }))
})

it('retain', function () {
return invoke(composer.retain(composer.try(() => ({ p: 4 }))), { n: 3 })
.then(activation => assert.deepEqual(activation.response.result, { params: { n: 3 }, result: { p: 4 } }))
})

it('invalid options', function () {
try {
invoke(composer.try('isNotOne', 'isNotOne', 'isNotOne'))
Expand Down