Invokes the next operation.
import Batch = require("nativescript-batch");
import Frame = require("ui/frame");
import HTTP = require("http");
var userListView = Frame.topmost().getViewById('myUserList');
var b = Batch.newBatch(function(ctx) {
// initialize async operations
});
for (var userId = 1; userId <= 100; userId++) {
b.items.push(userId);
b = b.then(function(ctx : Batch.IBatchOperationContext) {
var uid = ctx.items.getItem(ctx.index - 1).toString();
HTTP.request({
url: 'https://example.com/api/users/' + uid,
method: 'GET'
}).then(function(response) {
// handle response
ctx.invokeNext();
},
function(error) {
// handle error
ctx.invokeNext();
});
}).setInvokeStrategy(Batch.InvokeStrategy.Manually);
}
b.start();