相关疑难解决方法(0)

如何在JavaScript中阻止异步函数

我需要在JavaScript中编写一个函数,它从调用异步函数返回一个状态.但是,调用者只接收该值,并且不提供回调函数.我尝试过类似的东西:

function getState() {
    var ret = null;
    asyncCall("request",
        function() { ret = "foo"; } // callback
    );
    while (ret === null)
        ; // block on the asynchronous call
    return ret;
}
Run Code Online (Sandbox Code Playgroud)

然而,循环永远不会结束......

有任何想法吗?谢谢.

javascript asynchronous

10
推荐指数
1
解决办法
2万
查看次数

解释如何使用IndexedDB在此JavaScript代码中使用生成器?

同时通过IndexedDB的美妙的世界我的方式,我碰到像代码这个来自Mozilla的测试套件:

/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

var testGenerator = testSteps();

function testSteps()
{
  const IDBObjectStore = Components.interfaces.nsIIDBObjectStore;
  const name = this.window ? window.location.pathname : "Splendid Test";
  const description = "My Test Database";

  var data = [
    { name: "inline key; key generator",
      autoIncrement: true,
      storedObject: {name: "Lincoln"},
      keyName: "id",
      keyValue: undefined,
    },
    { name: "inline key; no key generator",
      autoIncrement: false,
      storedObject: {id: 1, name: "Lincoln"},
      keyName: "id",
      keyValue: undefined, …
Run Code Online (Sandbox Code Playgroud)

javascript generator indexeddb javascript-1.8

7
推荐指数
1
解决办法
1952
查看次数