S
S
Sinnk2020-04-22 15:41:47
JavaScript
Sinnk, 2020-04-22 15:41:47

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

2 answer(s)
I
Ivan Klimenko, 2020-04-22
@Sinnk

try {
    f();
    g();
    h();
} catch (e) {
    // ...
}

H
hzzzzl, 2020-04-22
@hzzzzl

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 question

Ask a Question

731 491 924 answers to any question