Execution value

If you want to define a value that is piped through the whole execution chain, you can use the value property of a batch execution context:

import Batch = require("nativescript-batch");

var b = Batch.newBatch(function(ctx) {
    // ctx.value = undefined
  
    ctx.value = 666:
}).then(function(ctx) {
    // ctx.value == 666
  
    // do something that does not change
    // the ctx.value property
}).then(function(ctx) {
    // ctx.value == 666
  
    // do something that does not change
    // the ctx.value property
}).then(function(ctx) {
    // ctx.value == 666
  
    ctx.value = "TM";
}).then(function(ctx) {
    // ctx.value == "TM"
});

b.start();

Result value

You can define a global result value for a start() call if you use the result property of a batch execution context:

import Batch = require("nativescript-batch");

var b = Batch.newBatch(function(ctx) {
    // ctx.prevValue = undefined
    ctx.result = 11;
}).then(function(ctx) {
    // something that does NOT set
    // ctx.result property
  
    // ctx.result == 11
}).then(function(ctx) {
    ++ctx.result;
    // ctx.result == 12
}).then(function(ctx) {
    ++ctx.result;
    // ctx.result == 13
}).then(function(ctx) {
    // something that does NOT set
    // ctx.result property
  
    // ctx.result == 13
});

// 13
var r = b.start();

Values for next operations

The nextValue property of a batch operation context can be used to define a value for an upcoming operation.

In the upcoming operation you can access the prevValue property.

These values will be resetted in the upcoming operation:

import Batch = require("nativescript-batch");

var b = Batch.newBatch(function(ctx) {
    // ctx.prevValue = undefined
    ctx.nextValue = "TM";
}).then(function(ctx) {
    // ctx.prevValue == "TM"
    
    // something that does NOT set
    // ctx.nextValue property
}).then(function(ctx) {
    // ctx.prevValue == undefined
  
    ctx.nextValue = "MK";
}).then(function(ctx) {
    // ctx.prevValue == "MK"
    
    ctx.nextValue = "YS";
}).then(function(ctx) {
    // ctx.prevValue == "YS"
});

b.start();