Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

worker Promise support?

1474608684

Edited 1474609040
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Do sheet workers support ES6 Promises? I'm trying to use Promises in a character sheet I'm developing, but even something as simple as the below doesn't seem to work: /**    * Promise-wrapped setAttrs.    */   function _setAttrs(values) {     return new Promise((resolve, reject) => {       setAttrs(values, undefined, () => {         resolve();       });     });   }   on('sheet:opened', () => {     Promise.resolve(42)     .then(value => {       return _setAttrs({         debug: value       });     })     .then(() => {       setAttrs({         debug: 11       });     });   }); The expected behavior is that debug is set to 11 after the sheet is opened. Instead, it gets set to 42, as if it is completely skipping calling the Promise's resolve function in _setAttrs().
1474637860

Edited 1474638569
Ada L.
Marketplace Creator
Sheet Author
API Scripter
In the following mocked-up test I built in the regular API, it works just fine. (() => {   'use strict';   /**    * Promise-wrapped setAttrs.    */   function _setAttrs(values) {     return new Promise((resolve, reject) => {       resolve('this is a test');     });   }   on('ready', () => {     Promise.resolve(42)     .then(value => {       return _setAttrs({         debug: value       });     })     .then(value => {       log(value);       return _setAttrs({         debug: 11       });     })     .catch(err => {       _setAttrs({         debug: err.toString()       });     });   }); })(); Here, the Promises get resolved and 'this is a test' is printed to the API log, as expected. The mocked-up test works fine in the web worker if I replace the 'ready' event with 'sheet:opened' and do setAttrs({debug: value}) instead of log(value). So it looks like the Promise implementation isn't the culprit. Maybe I've found a bug in setAttrs' callback?
1474666634
Lithl
Pro
Sheet Author
API Scripter
It may simply be that sheet workers and the API are running different engines, where one has Promise support and the other doesn't.