zoukankan      html  css  js  c++  java
  • lazy evaluation and deferring a computation await promise async

    Promise - JavaScript | MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

    Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future.

    Promise is in one of these states:

    • pending: initial state, neither fulfilled nor rejected.
    • fulfilled: meaning that the operation completed successfully.
    • rejected: meaning that the operation failed.

    await - JavaScript | MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

    async function - JavaScript | MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

    let myFirstPromise = new Promise((resolve, reject) => {
      // We call resolve(...) when what we were doing asynchronously was successful, and reject(...) when it failed.
      // In this example, we use setTimeout(...) to simulate async code. 
      // In reality, you will probably be using something like XHR or an HTML5 API.
      setTimeout(function(){
        resolve("Success!"); // Yay! Everything went well!
      }, 250);
    });
    
    myFirstPromise.then((successMessage) => {
      // successMessage is whatever we passed in the resolve(...) function above.
      // It doesn't have to be a string, but if it is only a succeed message, it probably will be.
      console.log("Yay! " + successMessage);
    });





  • 相关阅读:
    开发一个cube.js cratedb driver
    dremio 时间操作函数
    authelia web sso 解决方案
    dremio sql server 出现无法绑定由多个部分组成的标识符的解决方法
    cratedb 4.5 企业特性可以免费使用了
    cube.js 新版本cubestore 禁用
    spring-native 编译spring 应用为graalvm native 镜像
    streamsets tar 模式启动
    streamset data collector 新注册机制
    Swarm 集群管理
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9486625.html
Copyright © 2011-2022 走看看