Closed justdan23 closed 2 years ago
You can easily retrieve a promisified function with util.promisify()
https://nodejs.org/dist/latest-v14.x/docs/api/util.html#util_util_promisify_original.
const util = require('util')
const libre = require('libreoffice-convert');
const convert = util.promisify(libre.convert)
For this code to be reused in a Web Service capacity, the sequencing of the call to 'convert' and it's return callback both need to be managed to prevent premature returning.
A future improvement could be to migrate 'convert' away from callbacks and toward use of Promises where the final Promise is returned from 'convert' and thus use 'await' to control it without needing a wrapper Promise. However, the above code does work effectively to control the open source without modifying it.