javascript - weird ~infinite loop with $http.get -
i'm doing loop polling, wait events, , i'm having trouble infinite loop. here code:
var app = angular.module('mainapp', []); app.factory('userevents', function ($http) { var manageevent = function (event) { //do work here //and then, poll: window.settimeout(poll, 0); } var poll = function () { $http({ method: 'get', url: '/get-events', }) .success(function(event, status) { manageevent(event) }); } service = { poll: poll, } return service }); function maincontroller($scope, userevents) { userevents.poll(); }
once first event received success method of $http.get executed without request being done, creates loop. @ point magically stops, sending request. it's if function 'poll' using previous $http.get promise, resolved (???)
if set timeout of 200ms in 'manageevent' function, problem doesn't appear, it's not clean solution me.
can explain me what's happening here ?
thanks
Comments
Post a Comment