Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

awaitify.js 796B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = awaitify;
  6. // conditionally promisify a function.
  7. // only return a promise if a callback is omitted
  8. function awaitify(asyncFn, arity = asyncFn.length) {
  9. if (!arity) throw new Error('arity is undefined');
  10. function awaitable(...args) {
  11. if (typeof args[arity - 1] === 'function') {
  12. return asyncFn.apply(this, args);
  13. }
  14. return new Promise((resolve, reject) => {
  15. args[arity - 1] = (err, ...cbArgs) => {
  16. if (err) return reject(err);
  17. resolve(cbArgs.length > 1 ? cbArgs : cbArgs[0]);
  18. };
  19. asyncFn.apply(this, args);
  20. });
  21. }
  22. return awaitable;
  23. }
  24. module.exports = exports['default'];