如何在d3 v5中表达Promise队列 [英] how to express a queue of Promise in d3 v5
本文介绍了如何在d3 v5中表达Promise队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经阅读了这些答案,但无法解决:
I have already read these answers, but I wasn't able to solve:
d3.js v5-Promise.all已替换d3.queue
我在d3 v4中的代码如下
My code in d3 v4 looks like
d3.queue()
.defer(d3.json, "path/file.json")
.defer(populate,map,data)
.await(ready);
}
function populate(map,data,callback) {
.. code ..
callback(null);
}
function ready(error, topo) {
.. code ..
}
我想用Promise代替
I would like to replace this with Promise
推荐答案
我假设您的populate
函数返回topo.您可以使用承诺链:
I'm assuming your populate
function returns topo. You can use promise chaining:
function populate(map, data) {
.. code ..
return // return topo?
}
function ready(topo) {
// map
.. code ..
}
Promise.all([d3.json("path/file.json")])
.then(([data]) => populate(map, data))
.then(topo => {
ready(topo)
})
您可以正常返回该值,而无需使用回调来继续操作,并且该值将由链中的下一个函数获取.
Instead of doing continuation using a callback, you can return the value normally, and it'll be picked up by the next function in the chain.
这篇关于如何在d3 v5中表达Promise队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文