Skip to content

Instantly share code, notes, and snippets.

@parweb
Created December 1, 2016 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parweb/e69bf1f6dcebdd445f174ecd426f5534 to your computer and use it in GitHub Desktop.
Save parweb/e69bf1f6dcebdd445f174ecd426f5534 to your computer and use it in GitHub Desktop.
test-railway.js
const addOne = value => {
return value + 1;
};
const failIfOdd = value => {
return value + 1;
};
function railway ( chain ) {
return new Promise((resolve) => {
chain( val => new Promise( resolve => resolve( val ) ) )
.then( result => resolve( [ true, result ] ) )
.catch( error => resolve( [ false, error ] ) );
});
}
const [ ok, result ] = railway(
start => {
start( 1 )
.then( addOne )
.then( failIfOdd )
.then( addOne )
}
);
console.log(ok, result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment