What nodejs library is most like jQuery's defe

2019-01-14 06:06发布

I've become a skilled user of jQuery's new and amazing Deferred module, and as I'm easing into using more of Node.js, I find myself wanting something exactly like it in much of my Node.js programming: callbacks that block until a collection of promises devolves to resolved, with the freedom to add to the array on-the-fly as the task grows in complexity-- such as when one processes a tree of data, the size of which is not known at the start of the task.

But node-fibers requires a whole new executable, Q()'s interface is just damned confusing, and node-step only seems to handle single-task synchronizations.

Has someone just ported jQuery's Deferreds to a node-ready form? It doesn't seem that unlikely, nor does it seem that Deferreds is dependent upon DOM-available features, but I haven't found a server-side equivalent.

7条回答
Explosion°爆炸
2楼-- · 2019-01-14 06:41

This nodejs module is CommonJS compliant.

https://github.com/cujojs/when

查看更多
贪生不怕死
3楼-- · 2019-01-14 06:42

This wasn't around when the question was asked, but according to the readme it uses (and passes) the jquery tests. It appears to be exactly identical minus the (jQuery||$). prefix.

https://github.com/jaubourg/jquery-deferred-for-node

查看更多
萌系小妹纸
4楼-- · 2019-01-14 06:45

If you want the same API, there's nothing stopping you from using jQuery itself under Node. Just npm install jquery, then:

var $ = require('jquery');
var deferred = $.Deferred();
查看更多
我想做一个坏孩纸
5楼-- · 2019-01-14 06:50

This node library contains jquery 1.8.2 deferred class.

https://www.npmjs.com/package/jquery-deferred

npm install jquery-deferred

查看更多
再贱就再见
6楼-- · 2019-01-14 06:50

I don't think you can get any closer than jQuery deferred lib for nodeJS.

查看更多
不美不萌又怎样
7楼-- · 2019-01-14 06:53

Googling: deferred for nodejs

Gave me: https://github.com/felixge/node-deferred

Though not exactly what you are looking for, is moderately close. I find that the callback chaining is fairly natural, though deeply nested chains can be a bit difficult to keep up with.

Searching for: promise nodejs lead me down a path of more interesting results...

Both of which are probably much closer to what you are looking for. :)

查看更多
登录 后发表回答