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.

Thenable.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict'
  2. const constants = require('./constants')
  3. const unwrapSync = require('./unwrapSync')
  4. // Behaves like a Promise, though the then() and catch() methods are unbound and
  5. // must be called with the instance as their thisArg.
  6. //
  7. // The executor must either return a value or throw a rejection reason. It is
  8. // not provided resolver or rejecter methods. The executor may return another
  9. // thenable.
  10. class Thenable {
  11. constructor (executor) {
  12. try {
  13. this.result = unwrapSync(executor())
  14. this.state = constants.RESOLVED
  15. } catch (err) {
  16. this.result = err
  17. this.state = constants.REJECTED
  18. }
  19. }
  20. then (onFulfilled, onRejected) {
  21. if (this.state === constants.RESOLVED && typeof onFulfilled === 'function') {
  22. return new Thenable(() => onFulfilled(this.result))
  23. }
  24. if (this.state === constants.REJECTED && typeof onRejected === 'function') {
  25. return new Thenable(() => onRejected(this.result))
  26. }
  27. return this
  28. }
  29. catch (onRejected) {
  30. return this.then(null, onRejected)
  31. }
  32. }
  33. module.exports = Thenable