• Srinivas Shettigar
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am using Lightning frame to render d3 type of spider view UI, on click of nodes in the spider view, I am supposed to make as APEX call to fetch the JSON data to render the node. I have earlier called server side code using $A.enqueueAction(action), but when I perform the same within my filestore java script action.setCallback does not get called, it looks as if it has hit a dead lock. I have noticed one more behavior if I force the code to throw an exception the call-back gets called. It looks like Lightning framework has some limitation while making an asynchronous calls with in non-blocking function calls. I am attaching the code with 3 scenariosfor your perusal, if you could help me understand the behaviors of the code that will be of great help.
Scenario A : lightningAction.setCallback does not get called.

var paramss= JSON.stringify(params);
	var deferred = $.Deferred();
	var lightningAction = lightningComponent.get("c.invokeAppToolKitGet");			

	lightningAction.setParams({
		"parameters": paramss
	});

lightningAction.setCallback(this, function(response){
		var state = response.getState();														
		if (state === "SUCCESS") {  
			var calloutRes = response.getReturnValue();
			var callBackResponse = JSON.parse(calloutRes);
callBackResponse.data.data.entity = 
                   JSON.stringify(callBackResponse.data.data.entity);
			deferred.resolve(callBackResponse);
		}
		else{	
			deferred.reject('Error');								
		}  							
	});	
						
	$A.enqueueAction(lightningAction);		
						
	var promise = deferred.then(function(response) { 
		//Parse the response and build the node object
	}

	return promise;
Scenario B : Introduced $A.getCallback that throws an exception, with this change the call back get called, but the main code breaks since remaining code was not processed due to exeption.

var paramss= JSON.stringify(params);
	var deferred = $.Deferred();
	var lightningAction = lightningComponent.get("c.invokeAppToolKitGet");			

	lightningAction.setParams({
		"parameters": paramss
	});

lightningAction.setCallback(this, function(response){
		var state = response.getState();														
		if (state === "SUCCESS") {  
			var calloutRes = response.getReturnValue();
			var callBackResponse = JSON.parse(calloutRes);
callBackResponse.data.data.entity = 
                   JSON.stringify(callBackResponse.data.data.entity);
			deferred.resolve(callBackResponse);
		}
		else{	
			deferred.reject('Error');								
		}  							
	});	
						
	$A.enqueueAction(lightningAction);		
	
	$A.getCallback(function() {						
	});
					
	var promise = deferred.then(function(response) { 
		//Parse the response and build the node object
	}

	return promise;
Scenario C : The call back does not get called. Since we catch the exception and main code gets processed and call back in not getting called. It looks like Thread locking scenario in Java.

var paramss= JSON.stringify(params);
	var deferred = $.Deferred();
	var lightningAction = lightningComponent.get("c.invokeAppToolKitGet");			

	lightningAction.setParams({
		"parameters": paramss
	});

lightningAction.setCallback(this, function(response){
		var state = response.getState();														
		if (state === "SUCCESS") {  
			var calloutRes = response.getReturnValue();
			var callBackResponse = JSON.parse(calloutRes);
callBackResponse.data.data.entity = 
                   JSON.stringify(callBackResponse.data.data.entity);
			deferred.resolve(callBackResponse);
		}
		else{	
			deferred.reject('Error');								
		}  							
	});	
						
	$A.enqueueAction(lightningAction);		
	
try{
		$A.getCallback(function() {						
		});
	catch(error){
		log.error("Dummy", "Error " + error);
	}
					
	var promise = deferred.then(function(response) { 
		//Parse the response and build the node object
	}

	return promise;



 
I am using Lightning frame to render d3 type of spider view UI, on click of nodes in the spider view, I am supposed to make as APEX call to fetch the JSON data to render the node. I have earlier called server side code using $A.enqueueAction(action), but when I perform the same within my filestore java script action.setCallback does not get called, it looks as if it has hit a dead lock. I have noticed one more behavior if I force the code to throw an exception the call-back gets called. It looks like Lightning framework has some limitation while making an asynchronous calls with in non-blocking function calls. I am attaching the code with 3 scenariosfor your perusal, if you could help me understand the behaviors of the code that will be of great help.
Scenario A : lightningAction.setCallback does not get called.

var paramss= JSON.stringify(params);
	var deferred = $.Deferred();
	var lightningAction = lightningComponent.get("c.invokeAppToolKitGet");			

	lightningAction.setParams({
		"parameters": paramss
	});

lightningAction.setCallback(this, function(response){
		var state = response.getState();														
		if (state === "SUCCESS") {  
			var calloutRes = response.getReturnValue();
			var callBackResponse = JSON.parse(calloutRes);
callBackResponse.data.data.entity = 
                   JSON.stringify(callBackResponse.data.data.entity);
			deferred.resolve(callBackResponse);
		}
		else{	
			deferred.reject('Error');								
		}  							
	});	
						
	$A.enqueueAction(lightningAction);		
						
	var promise = deferred.then(function(response) { 
		//Parse the response and build the node object
	}

	return promise;
Scenario B : Introduced $A.getCallback that throws an exception, with this change the call back get called, but the main code breaks since remaining code was not processed due to exeption.

var paramss= JSON.stringify(params);
	var deferred = $.Deferred();
	var lightningAction = lightningComponent.get("c.invokeAppToolKitGet");			

	lightningAction.setParams({
		"parameters": paramss
	});

lightningAction.setCallback(this, function(response){
		var state = response.getState();														
		if (state === "SUCCESS") {  
			var calloutRes = response.getReturnValue();
			var callBackResponse = JSON.parse(calloutRes);
callBackResponse.data.data.entity = 
                   JSON.stringify(callBackResponse.data.data.entity);
			deferred.resolve(callBackResponse);
		}
		else{	
			deferred.reject('Error');								
		}  							
	});	
						
	$A.enqueueAction(lightningAction);		
	
	$A.getCallback(function() {						
	});
					
	var promise = deferred.then(function(response) { 
		//Parse the response and build the node object
	}

	return promise;
Scenario C : The call back does not get called. Since we catch the exception and main code gets processed and call back in not getting called. It looks like Thread locking scenario in Java.

var paramss= JSON.stringify(params);
	var deferred = $.Deferred();
	var lightningAction = lightningComponent.get("c.invokeAppToolKitGet");			

	lightningAction.setParams({
		"parameters": paramss
	});

lightningAction.setCallback(this, function(response){
		var state = response.getState();														
		if (state === "SUCCESS") {  
			var calloutRes = response.getReturnValue();
			var callBackResponse = JSON.parse(calloutRes);
callBackResponse.data.data.entity = 
                   JSON.stringify(callBackResponse.data.data.entity);
			deferred.resolve(callBackResponse);
		}
		else{	
			deferred.reject('Error');								
		}  							
	});	
						
	$A.enqueueAction(lightningAction);		
	
try{
		$A.getCallback(function() {						
		});
	catch(error){
		log.error("Dummy", "Error " + error);
	}
					
	var promise = deferred.then(function(response) { 
		//Parse the response and build the node object
	}

	return promise;