promise.js 939 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /**
  3. Part of Zombie Navigator
  4. Copyright © 2015 Zombie Navigator Developers
  5. @file
  6. @license AGPL-3.0+
  7. */
  8. /*
  9. Zombie script example (= unprivileged)
  10. Do NOT require () this script from the addon code.
  11. A basic example of a Zombie script
  12. */
  13. const {zombie, console} = require('zombie/zombie');
  14. const {openWindow, closeAll} = require('zombie/webbrowser');
  15. const {run} = require('zombie/async');
  16. try {
  17. run(function* () {
  18. try {
  19. yield new Promise(function (resolve, reject) {
  20. reject(new Error('Error!'));
  21. });
  22. } catch (e) {
  23. console.log('Error inside coroutine:', e);
  24. closeAll();
  25. let result = yield new Promise(function (resolve, reject) {
  26. resolve(42);
  27. });
  28. console.log('result:', result);
  29. throw e;
  30. }
  31. })
  32. .catch(function (e) {
  33. console.log('Error via promise:', e + '');
  34. closeAll();
  35. });
  36. } catch (e) {
  37. console.log('Error:', e + '');
  38. closeAll();
  39. }
  40. // vim: ts=4 noet ai