javascript - d3.queue.await 函数未被调用

标签 javascript d3.js async-await deferred

为什么在这个非常小的示例中没有调用 .await 函数?

http://jsfiddle.net/x2fkvsco/

HTML

<h1>test</h1>
<div id="a"></div>
<div id="b"></div>

JS

d3.queue()
   .defer(a,1)
   .await(b,2);

function a(x){
    d3.select('#a').text("a is executing with x="+x);
}

function b(err,x){
   d3.select('#b').text("b is executing with x="+x);
}

输出

test
a is executing with x=1

最佳答案

@altocumulus 用他富有洞察力的评论打败了我,但是因为一个例子说明了一千个字:

<!DOCTYPE html>
<html>

<head>
  <script src="https://d3js.org/d3.v4.min.js"></script>
</head>

<body>
  <h1>test</h1>
  <div id="a"></div>
  <div id="b"></div>
  <script>
    var q = d3.queue()
      .defer(a, 1, 2)
      .await(b);

    function a(x, y, callback) {
      d3.select('#a').text("a is executing with x=" + x);
      callback(null, y);
    }

    function b(err, x) {
      d3.select('#b').text("b is executing with x=" + x);
    }
  </script>
</body>

</html>

关于javascript - d3.queue.await 函数未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44312383/

相关文章:

javascript - d3js 为时间刻度轴设置 tickValues

javascript - 如何将(鼠标)事件添加到 SVG 的 XMLDocument

c# - 如何知道创建的线程数并相应地限制任务

c# - 异步 I/O 方法是如何处理的

javascript - 自定义忘记密码电子邮件.Meteorjs

javascript - jQuery(function) 或 $(function) 是做什么的?

javascript - 屏幕加载后如何停止加载动画

javascript - 获取 HTML 选择元素的预选值

d3.js - 在 D3 + Leaflet 中动画化 GeoJSON 路径

JavaScript,异步,等待 : can't extract value into class variable