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.

async.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.maybeAsync = maybeAsync;
  6. exports.forwardAsync = forwardAsync;
  7. exports.isThenable = isThenable;
  8. exports.waitFor = exports.onFirstPause = exports.isAsync = void 0;
  9. function _gensync() {
  10. const data = require("gensync");
  11. _gensync = function () {
  12. return data;
  13. };
  14. return data;
  15. }
  16. const id = x => x;
  17. const runGenerator = _gensync()(function* (item) {
  18. return yield* item;
  19. });
  20. const isAsync = _gensync()({
  21. sync: () => false,
  22. errback: cb => cb(null, true)
  23. });
  24. exports.isAsync = isAsync;
  25. function maybeAsync(fn, message) {
  26. return _gensync()({
  27. sync(...args) {
  28. const result = fn.apply(this, args);
  29. if (isThenable(result)) throw new Error(message);
  30. return result;
  31. },
  32. async(...args) {
  33. return Promise.resolve(fn.apply(this, args));
  34. }
  35. });
  36. }
  37. const withKind = _gensync()({
  38. sync: cb => cb("sync"),
  39. async: cb => cb("async")
  40. });
  41. function forwardAsync(action, cb) {
  42. const g = _gensync()(action);
  43. return withKind(kind => {
  44. const adapted = g[kind];
  45. return cb(adapted);
  46. });
  47. }
  48. const onFirstPause = _gensync()({
  49. name: "onFirstPause",
  50. arity: 2,
  51. sync: function (item) {
  52. return runGenerator.sync(item);
  53. },
  54. errback: function (item, firstPause, cb) {
  55. let completed = false;
  56. runGenerator.errback(item, (err, value) => {
  57. completed = true;
  58. cb(err, value);
  59. });
  60. if (!completed) {
  61. firstPause();
  62. }
  63. }
  64. });
  65. exports.onFirstPause = onFirstPause;
  66. const waitFor = _gensync()({
  67. sync: id,
  68. async: id
  69. });
  70. exports.waitFor = waitFor;
  71. function isThenable(val) {
  72. return !!val && (typeof val === "object" || typeof val === "function") && !!val.then && typeof val.then === "function";
  73. }