Canceling asynchronous methods

Description

Use the Cancel method to cancel an asynchronous method call to a Service API. Each asynchronous call has a TransactionID (number) associated with it. This ID is passed as an input parameter to the Cancel method.

After completing the cancel operation, the callback method onResponse is called to notify this event.

Syntax

var serviceInstance = new Service("ServiceProvider", "Interface");
var inParams = new Object;
var outParams = serviceInstance.AsyncOperation(inParams, onResponse);
var transactionID:Number = outParams.TransactionID;
var bool:Boolean = false;
bool = serviceInstance.Cancel(transactionID);
if (bool)
{
  // Cancelling has started.
}
function onResponse(transactionID:Number, eventID:String, outParam:Object)
{
  if (eventID == "cancel")
  {
    // The ongoing event is cancelled.
  }
}

Example code

The following code snippet shows how to send and cancel an SMS message asynchronously:

import com.nokia.lib.Service;
var messaging = new Service("Service.Messaging", "IMessaging");
var inParams = {
  MessageType:"SMS",
  To:"9999999999",
  BodyText:"Hi"
};
var outParams = messaging.Send(inParams, onResponse);
var transactionID:String = outParams.TransactionID;
var bool:Boolean = messaging.Cancel(transactionID);
if (bool)
{
  // Cancelling has started.
}
function onResponse(transactionID:Number, eventID:String, outParam:Object)
{
  if (eventID == "cancel")
  {
    // Callback to notify cancel event.
  }
}