Idiomatic way to wait for multiple callbacks in Node.js

前端 未结 8 2239
旧巷少年郎
旧巷少年郎 2020-11-28 04:12

Suppose you need to do some operations that depend on some temp file. Since we\'re talking about Node here, those operations are obviously asynchronous. What is the idiomati

8条回答
  •  悲哀的现实
    2020-11-28 04:24

    // simple countdown latch
    function CDL(countdown, completion) {
        this.signal = function() { 
            if(--countdown < 1) completion(); 
        };
    }
    
    // usage
    var latch = new CDL(10, function() {
        console.log("latch.signal() was called 10 times.");
    });
    

提交回复
热议问题