Answer the question
In order to leave comments, you need to log in
How to implement pipelining of javascript functions?
I really liked the structure of the
then -> then -> then promises and the catch error handling
Or I saw "pipes" in Gulp (pipe)
Is there something similar natively in Javascript for synchronous code?
When there is a function, if it is executed successfully, the second one is executed, and so on
. And if an error occurred in one of the functions, then the function for exceptions is executed.
Answer the question
In order to leave comments, you need to log in
so they are by default one after the other and are executed the same
function add(x, y) { return x + y }
function div(x, y) {
if(y === 0) throw new Error('div by zero')
return x / y
}
try {
const sum = add(10, 100)
const result = div(sum, sum - sum)
console.log('result!', result)
} catch(e) {
console.log('omg')
console.log(e)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question