'Add Promise-Chain part in reuseable function

I got a bunch of functions which consist of a simple promise-chain which is mostly individual, anyway for all my functions a small block in the promise-chain is the same for all chains.

Example:

function A() {
  DoSomethingA()
    .then(/* specific then block */)
    .then(/* general then block */)
    .then(/* general then block */)
    .then(/* specific then block */)
}

function B() {
  DoSomethingB()
    .then(/* specific then block */)
    .then(/* general then block */)
    .then(/* general then block */)
}

Now I want to have the "general then block" part be reusable variable/function so I can edit it for all functions at once when required. I just miss how I might handle this in the simplest way. Before and after the "general-then-blocks" there might be a undefined amount of "specific then blocks". The "general then blocks" always appear in this given order and always are exactly after each other.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source