Sha256: ab183a48c61c15ee7f666e94dfd8e071ed17d3eed9e7fcefc2f351ef1f59d9e9

Contents?: true

Size: 811 Bytes

Versions: 11

Compression:

Stored size: 811 Bytes

Contents

'use strict'

module.exports.disposer = disposer

function disposer (creatorFn, disposerFn, fn) {
  const runDisposer = (resource, result, shouldThrow = false) => {
    return disposerFn(resource)
      .then(
        // disposer resolved, do something with original fn's promise
        () => {
          if (shouldThrow) {
            throw result
          }
          return result
        },
        // Disposer fn failed, crash process
        (err) => {
          throw err
          // Or process.exit?
        })
  }

  return creatorFn
    .then((resource) => {
      // fn(resource) can throw, so wrap in a promise here
      return Promise.resolve().then(() => fn(resource))
        .then((result) => runDisposer(resource, result))
        .catch((err) => runDisposer(resource, err, true))
    })
}

Version data entries

11 entries across 9 versions & 5 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/cacache/lib/util/disposer.js
tang-0.2.1 spec/tang_app/node_modules/cacache/lib/util/disposer.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/cacache/lib/util/disposer.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/cacache/lib/util/disposer.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/compression-webpack-plugin/node_modules/cacache/lib/util/disposer.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/cacache/lib/util/disposer.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/cacache/lib/util/disposer.js
tang-0.2.0 spec/tang_app/node_modules/cacache/lib/util/disposer.js
tang-0.1.0 spec/tang_app/node_modules/cacache/lib/util/disposer.js
tang-0.0.9 spec/tang_app/node_modules/cacache/lib/util/disposer.js
enju_library-0.3.8 spec/dummy/node_modules/cacache/lib/util/disposer.js