Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Bluebird Removal): Remove Bluebird from index #88

Merged
merged 9 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
sudo apt-get -y install \
libpoppler-cpp-dev \
libpoppler-private-dev \
g++
# Setup this version of Node
# Cache is saved and restored by actions/setup-node
- name: Use Node ${{ matrix.node-version }}
Expand Down
36 changes: 21 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
'use strict';

var fs = require('fs');
var Promise = require('bluebird');
var popen = Promise.promisify(fs.open);
var pclose = Promise.promisify(fs.close);
var util = require('util');
var popen = util.promisify(fs.open);
var pclose = util.promisify(fs.close);
var detect = require('./detect');

function measure (plugins, path, callback) {
async function measure (plugins, path, callback) {
var fileDescriptor;

return popen(path, 'r')
.then(function (fd) {
try {
const fd = await popen(path, 'r');
fileDescriptor = fd;
return detect(fd, plugins);
})
.then(function (plugin) {
return plugin.measure(path, fileDescriptor);
})
.finally(function () {
const plugin = await detect(fd, plugins);

if (callback) return callback(undefined, await plugin.measure(path, fileDescriptor));

const measurement = await plugin.measure(path, fileDescriptor);
return measurement;
}
catch (err) {
if (callback) callback(err, undefined);

throw err;
}
finally {
if (fileDescriptor) {
return pclose(fileDescriptor);
pclose(fileDescriptor);
}
})
.asCallback(callback);
}
}

module.exports = function () {
Expand Down
Loading