Does Google Apps Script V8 engine support Promise?

一个人想着一个人 提交于 2020-07-09 13:20:29

问题


They say V8 engine is a proper Javascript ES5 engine. Does it support ES5 features like Promise?


回答1:


Apps script V8 recognizes the new function definition formats, for example:

let letAsyncFunction = async function() { //Your logic here }

It asynchronously returns the result of the function evaluations, pretty much like a Promise.

In other words, when the function async is called, it returns a promise. Also await is used for calling an async function and wait for it to resolve or reject


References:

  • async function
  • V8 runtime Overview



回答2:


No. Promises are not functionally supported. But all promises related syntax doesn't throw any errors. However everything runs synchronously.

async function promise1_() {
  Logger.log("Start")
  Utilities.sleep(10000);
  return "done";
}

function test1(){
  promise1_();
  Logger.log("End")
}

If promises worked, "End" should be logged before "Start", but that's not the case.



来源:https://stackoverflow.com/questions/61578224/does-google-apps-script-v8-engine-support-promise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!