Skip to content

Commit

Permalink
Attempt to fix redux-saga#152
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Mar 1, 2016
1 parent 6a7a304 commit f3d4bac
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/internal/proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,13 @@ export default function proc(
}

function runCallEffect({context, fn, args}, effectId, cb) {
const result = fn.apply(context, args)
let result
try {
result = fn.apply(context, args)
}
catch(e) {
return cb(e)
}
return (
is.promise(result) ? resolvePromise(result, cb)
: is.iterator(result) ? resolveIterator(result, effectId, fn.name, cb)
Expand Down
89 changes: 89 additions & 0 deletions test/proc/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,92 @@ test('processor declarative call handling', assert => {
}, DELAY)

});





test('processor handles failure correctly when parent generator call child generator 1', assert => {
assert.plan(1);

let actual = []
const dispatch = v => actual.push(v)

function fail(message) {
throw new Error(message)
}

function* genFnChild() {
try {
yield io.put("startChild")
yield io.call(fail,"child error")
yield io.put("success child")
}
catch (e) {
yield io.put("failure child")
}
}

function* genFnParent() {
try {
yield io.put("start parent")
yield io.call(genFnChild)
yield io.put("success parent")
}
catch (e) {
yield io.put("failure parent")
}
}

proc(genFnParent(),undefined,dispatch).done.catch(err => assert.fail(err))

const expected = ['start parent','startChild','failure child','success parent']
setTimeout(() => {
assert.deepEqual(actual, expected,"processor dispatches appropriate actions")
assert.end()
}, DELAY)

});

test('processor handles failure correctly when parent generator call child generator 2', assert => {
assert.plan(1);

let actual = []
const dispatch = v => actual.push(v)

function fail(message) {
throw new Error(message)
}

function* genFnChild() {
try {
yield io.put("startChild")
yield io.call(fail,"child error")
yield io.put("success child")
}
catch (e) {
yield io.put("failure child")
throw e;
}
}

function* genFnParent() {
try {
yield io.put("start parent")
yield io.call(genFnChild)
yield io.put("success parent")
}
catch (e) {
yield io.put("failure parent")
}
}

proc(genFnParent(),undefined,dispatch).done.catch(err => assert.fail(err))

const expected = ['start parent','startChild','failure child','failure parent']
setTimeout(() => {
assert.deepEqual(actual, expected,"processor dispatches appropriate actions")
assert.end()
}, DELAY)

});

0 comments on commit f3d4bac

Please sign in to comment.