Skip to content

Commit 1861308

Browse files
committed
Issue jakesgordon#106 - a rejected async lifecycle event should throw an exception
1 parent 9143d57 commit 1861308

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/jsm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ mixin(JSM.prototype, {
108108

109109
beginTransit: function() { this.pending = true; },
110110
endTransit: function(result) { this.pending = false; return result; },
111+
failTransit: function(result) { this.pending = false; throw result; },
111112
doTransit: function(lifecycle) { this.state = lifecycle.to; },
112113

113114
observe: function(args) {
@@ -153,7 +154,7 @@ mixin(JSM.prototype, {
153154
result = observer[event].apply(observer, args);
154155
if (result && typeof result.then === 'function') {
155156
return result.then(this.observeEvents.bind(this, events, args, event))
156-
.catch(this.endTransit.bind(this))
157+
.catch(this.failTransit.bind(this))
157158
}
158159
else if (result === false) {
159160
return this.endTransit(false);

test/lifecycle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ test('lifecycle events can be cancelled using a promise', t => {
587587
}
588588

589589
fsm.step('additional', 'arguments')
590-
.then(done)
590+
.then(function() { done('promise was rejected so this should never happen'); })
591+
.catch(done)
591592

592593
})
593594
})

0 commit comments

Comments
 (0)