https://github.com/Gozala/reducers
Tip revision: 291e0255e28ba6c015b69cc8556a287f9c873b9e authored by Irakli Gozalishvili on 25 October 2012, 06:36:51 UTC
Version 0.1.4
Version 0.1.4
Tip revision: 291e025
capture.js
"use strict";
var convert = require("./convert")
var accumulate = require("./accumulate")
var error = require("./error")
function capture(source, recover) {
/**
Creates and returns safe version of given `source` sequence, by using
`recover` function to recover from errors that may occur while reducing
a `source`. This is a mechanism for error handling and recovery for streams
that representing IO operations like (XHR / WebSockets etc...) where errors
may occur.
**/
return convert(source, function(self, next, initial) {
accumulate(source, function(value, result) {
if (value && value.is === error) {
accumulate(recover(value.value, result), next, result)
} else {
next(value, result)
}
}, initial)
})
}
module.exports = capture