javascript有定时器功能吗?

时间:2017-10-14 07:44:18

标签: javascript timer dojo intervals

解释这个问题。我有一个dojo工具包代码,它每1秒轮询一次open-monica服务器以在屏幕上显示该值。我试图发出警报,每40秒和60秒检查一次值。因此,我想知道是否有一个函数可以与dojo工具包的被动轮询一起运行。我尝试过setInterval()和setTimeout()但是这两个都停止了对monica服务器的轮询

我的代码是:

require(["dojo/dom-attr", "atnf/monica", "dojo/domReady!"], function(domAttr, monica) {

function valCheck(){

}
    // The callback is called separately for each point
    // that has new data, so we only need to accept the reference to that
    // point as an argument.
    var pageUpdate = function(pointReference) {
        var values = pointReference.latestValue(); //obtain the updated values

        domAttr.set("htmlPageDiv", "innerHTML", values.value); //display the moniva value in their corresponding div in the html page
        }
    };

    // We set up the connection to the MoniCA server.
    var monicaServer = monica.server({
        'webserverName': "some server",
        'serverName': "serverName",
        "webserverPath": "webServerPath",
        'updateInterval': 1000, // in ms
        'autoDescriptions': true
    });

    // Connect to it now, and when that is done, tell it which
    // points we want to query.
    monicaServer.connect().then(function(serverObj) {

        //add monica points to check in the server
        var points = monicaServer.addPoints(["some data point", "another data point", "etc."]);
        // Tell the server connector which function to call on each
        // update, for each point (we use the same callback for each.
        for (var i = 0; i < points.length; i++) {
            points[i].addCallback(pageUpdate);
        }
        // Get the descriptions and then start updating.
        monicaServer.getDescriptions();
        monicaServer.startUpdating();
    });
});

0 个答案:

没有答案