How to use the comb.when function in comb

To help you get started, we’ve selected a few comb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github C2FO / patio / test / migrations / files / bad_up_migration / 0.create_tables.js View on Github external
exports.up = function (db) {
    return comb.when(
        db.createTable("test", function () {
            this.column("column", "integer");
        }),
        db.createTable("test2", function () {
            this.column("column", "integer");
        }),
        db.createTable("test3", function () {
            this.column("column", "integer");
        }),
        db.createTable("test4", function () {
            this.column("column", "integer");
        })
    );
};
github C2FO / werker / lib / pool / pool.js View on Github external
this.__ttlTimer = setTimeout(function checkWorkers() {
                    LOGGER.debug("cleaning up workers");
                    var worker, fQueue = this.__freeObjects, workers = fQueue.values, ps = [];
                    for (var i = 0, l = workers.length; i < l; i++) {
                        worker = workers[i];
                        var lastUsed = worker.__lastUsed__;
                        LOGGER.debug("%d workers lifetime is %d", worker.pid, (Date.now() - lastUsed));
                        if (comb.isNumber(lastUsed) && (Date.now() - lastUsed) > maxTtl) {
                            LOGGER.debug("closing %d", worker.pid);
                            ps.push(this.closeWorker(worker));
                            fQueue.remove(worker);
                        }

                    }
                    LOGGER.debug("closing %d workers", ps.length);
                    comb.when(ps).chain(function () {
                        LOGGER.debug("done closing %d workers", ps.length);
                        setTimeout(checkWorkers.bind(this), maxTtl);
                    }.bind(this), function (err) {
                        console.error(err);
                        LOGGER.error(err);
                        setTimeout(checkWorkers.bind(this), maxTtl);
                    }.bind(this))
                }.bind(this), maxTtl);
            }
github C2FO / patio / example / associations / manyToMany.example.js View on Github external
}).chain(comb.hitch(classDs, "forEach", function (cls) {
            console.log(format('"%s" has the following students enrolled: \n\t-%s', cls.name, cls.students.map(
                function (student) {
                    return format("%s %s", student.firstName, student.lastName);
                }).join("\n\t-")));
            return comb.when(cls.aboveAverageStudents, cls.averageStudents, cls.belowAverageStudents, function (res) {
                var aboveAverage = res[0].map(
                        function (student) {
                            return format("%s %s", student.firstName, student.lastName);
                        }).join("\n\t-"),
                    average = res[1].map(
                        function (student) {
                            return format("%s %s", student.firstName, student.lastName);
                        }).join("\n\t-"),
                    belowAverage = res[2].map(
                        function (student) {
                            return format("%s %s", student.firstName, student.lastName);
                        }).join("\n\t-");

                console.log(format('"%s" has the following above average students enrolled: \n\t-%s', cls.name, aboveAverage));
                console.log(format('"%s" has the following average students enrolled: \n\t-%s', cls.name, average));
                console.log(format('"%s" has the following below average students enrolled: \n\t-%s', cls.name, belowAverage));
github C2FO / patio / example / model.multiDB.example.js View on Github external
connectAndCreateSchema().chain(function () {
    var myUser1 = new User1({
        firstName: "Bob1",
        lastName: "Yukon1",
        password: "password",
        dateOfBirth: new Date(1980, 8, 29)
    });
    var myUser2 = new User2({
        firstName: "Bob2",
        lastName: "Yukon2",
        password: "password",
        dateOfBirth: new Date(1980, 8, 29)
    });
    comb.when(myUser1.save(), myUser2.save(), function () {
        console.log(format("%s %s was created at %s", myUser1.firstName, myUser1.lastName, myUser1.created.toString()));
        console.log(format("%s %s's id is %d", myUser1.firstName, myUser1.lastName, myUser1.id));

        console.log(format("%s %s was created at %s", myUser2.firstName, myUser2.lastName, myUser2.created.toString()));
        console.log(format("%s %s's id is %d", myUser2.firstName, myUser2.lastName, myUser2.id));
        disconnect();
    }, disconnectError);
    //save the user
}, disconnectError);
github C2FO / patio / example / associations / manyToMany.alternateJoinTable.example.js View on Github external
}).chain(comb.hitch(classDs, "forEach", function (cls) {
            console.log(format('"%s" has the following students enrolled: \n\t-%s', cls.name, cls.students.map(function (student) {
                return format("%s %s", student.firstName, student.lastName);
            }).join("\n\t-")));
            return comb.when(cls.aboveAverageStudents, cls.averageStudents, cls.belowAverageStudents).chain(function (res) {
                var aboveAverage = res[0].map(
                        function (student) {
                            return format("%s %s", student.firstName, student.lastName);
                        }).join("\n\t-"),
                    average = res[1].map(
                        function (student) {
                            return format("%s %s", student.firstName, student.lastName);
                        }).join("\n\t-"),
                    belowAverage = res[2].map(
                        function (student) {
                            return format("%s %s", student.firstName, student.lastName);
                        }).join("\n\t-");

                console.log(format('"%s" has the following above average students enrolled: \n\t-%s', cls.name, aboveAverage));
                console.log(format('"%s" has the following average students enrolled: \n\t-%s', cls.name, average));
                console.log(format('"%s" has the following below average students enrolled: \n\t-%s', cls.name, belowAverage));
github C2FO / patio / example / associations / oneToMany.alternateKeys.example.js View on Github external
function () {
            return comb.when(
                DB.createTable("biologicalFather", function () {
                    this.primaryKey("id");
                    this.name(String);
                }),

                DB.createTable("stepFather", function () {
                    this.primaryKey("id");
                    this.name(String, {unique: true});
                })
            );
        },
        function () {
github C2FO / patio / example / associations / manyToMany.alternatePrimaryKeys.example.js View on Github external
classYear: "Junior"
        },
        {
            firstName: "Kim",
            lastName: "Bim",
            gpa: 2.24,
            classYear: "Senior"
        },
        {
            firstName: "Alex",
            lastName: "Young",
            gpa: 1.9,
            classYear: "Freshman"
        }
    ]);
    return comb.when(classInsertPromise, studentInsertPromise);
};
github doug-martin / ssrs / lib / util / iterablePromise.js View on Github external
this.addCallback(function (res) {
                if (isArray(res)) {
                    var l = res.length;
                    (function next(i) {
                        if (i < l) {
                            comb.when(cb(res[i], i, res)).then(function () {
                                process.nextTick(partial(next, ++i));
                            }, ret);
                        } else {
                            ret.callback(res);
                        }
                    })(0);
                } else {
                    comb.when(cb(res), 0, [res]).then(hitchIgnore(ret, "callback", res), ret);
                }
            });
            ret.addErrback(errback);
github C2FO / patio / example / associations / manyToMany.example.js View on Github external
.chain(function (res) {

        var classDs = Class.order("name"), studentDs = Student.order("firstName", "lastName");

        //Retrieve All classes and students
        return comb.when(classDs.all(), studentDs.all()).chain(function (results) {
            //enroll the students
            var classes = results[0], students = results[1];
            return comb.async.array(students).map(function (student, i) {
                if (i === 0) {
                    return student.enroll(classes);
                } else if (i < classes.length) {
                    return student.enroll(classes.slice(i));
                }
            })
                .chain(function () {
                    return Student.save({
                        firstName: "Zach",
                        lastName: "Igor",
                        gpa: 2.754,
                        classYear: "Sophmore",
                        classes: [
github C2FO / patio / example / associations / manyToMany.alternatePrimaryKeys.example.js View on Github external
function () {
            return comb.when(
                DB.createTable("class", function () {
                    this.primaryKey("id");
                    this.semester("char", {size: 10});
                    this.name(String);
                    this.subject(String);
                    this.description("text");
                    this.graded(Boolean, {"default": true});
                }),
                DB.createTable("student", function () {
                    this.primaryKey("id");
                    this.firstName(String);
                    this.lastName(String);
                    //GPA
                    this.gpa(sql.Decimal, {size: [1, 3], "default": 0.0});
                    //Honors Program?
                    this.isHonors(Boolean, {"default": false});