Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

node.js - What nodejs library is most like jQuery's deferreds?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...