2014-09-07 2 views
0

В Parse Documentation on background jobs есть выражение, беспокоящее меня.Счетчик в фоновом режиме

if (counter % 100 === 0) { 
    // Set the job's progress status 
    status.message(counter + " users processed."); 
    } 
    counter += 1; 

Может ли кто-нибудь объяснить эту часть? Особенно первая строка. Благодаря! Также, как лучше всего назвать работу в Xamarin?

Parse.Cloud.job("userMigration", function(request, status) { 
// Set up to modify user data 
Parse.Cloud.useMasterKey(); 
var counter = 0; 
// Query for all users 
var query = new Parse.Query(Parse.User); 
query.each(function(user) { 
    // Update to plan value passed in 
    user.set("plan", request.params.plan); 
    if (counter % 100 === 0) { 
    // Set the job's progress status 
    status.message(counter + " users processed."); 
    } 
    counter += 1; 
    return user.save(); 
}).then(function() { 
// Set the job's success status 
status.success("Migration completed successfully."); 
}, function(error) { 
// Set the job's error status 
    status.error("Uh oh, something went wrong."); 
    }); 
}); 
+1

http://ru.wikipedia.org/wiki/Modulo_operation – Rob

ответ

0

Как указал Роб, это операция по модулю, остальная часть в целых делениях. Таким образом, (counter % 100 === 0) будет истинным, если счетчик равен 0, 100, 200, 300 ... Они делают это, потому что не хотят наводнять вас сообщениями. Достаточно дать вам сообщение для каждого сотого пользователя.

Смежные вопросы