Click here to Skip to main content
15,884,176 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Attempted to register a view with an id already in use: 2 - EmberJs Pin
Natalie-9015-Dec-19 5:11
Natalie-9015-Dec-19 5:11 
GeneralRe: Attempted to register a view with an id already in use: 2 - EmberJs Pin
jkirkerx11-Dec-19 12:23
professionaljkirkerx11-Dec-19 12:23 
GeneralRe: Attempted to register a view with an id already in use: 2 - EmberJs Pin
simpledeveloper12-Dec-19 6:22
simpledeveloper12-Dec-19 6:22 
AnswerRe: Attempted to register a view with an id already in use: 2 - EmberJs Pin
Pete O'Hanlon12-Dec-19 0:02
mvePete O'Hanlon12-Dec-19 0:02 
GeneralRe: Attempted to register a view with an id already in use: 2 - EmberJs Pin
simpledeveloper12-Dec-19 6:26
simpledeveloper12-Dec-19 6:26 
QuestionI need to add “Add new item” option in Select2 Pin
Shraddha_Patel3-Dec-19 17:32
Shraddha_Patel3-Dec-19 17:32 
AnswerRe: I need to add “Add new item” option in Select2 Pin
phil.o3-Dec-19 21:45
professionalphil.o3-Dec-19 21:45 
SuggestionRe: I need to add “Add new item” option in Select2 Pin
ZurdoDev4-Dec-19 2:52
professionalZurdoDev4-Dec-19 2:52 
AnswerRe: I need to add “Add new item” option in Select2 Pin
simpledeveloper10-Dec-19 14:26
simpledeveloper10-Dec-19 14:26 
AnswerRe: I need to add “Add new item” option in Select2 Pin
Member 1469087415-Dec-19 23:13
Member 1469087415-Dec-19 23:13 
QuestionHow to include random password in email text message Pin
freezers30-Nov-19 19:44
freezers30-Nov-19 19:44 
QuestionRe: How to include random password in email text message Pin
ZurdoDev3-Dec-19 8:00
professionalZurdoDev3-Dec-19 8:00 
AnswerRe: How to include random password in email text message Pin
freezers4-Dec-19 6:42
freezers4-Dec-19 6:42 
AnswerRe: How to include random password in email text message Pin
F-ES Sitecore3-Dec-19 22:56
professionalF-ES Sitecore3-Dec-19 22:56 
GeneralRe: How to include random password in email text message Pin
freezers4-Dec-19 6:42
freezers4-Dec-19 6:42 
QuestionJavascript: indicate when item in a list clicked? Pin
Xarzu30-Nov-19 2:11
Xarzu30-Nov-19 2:11 
QuestionRe: Javascript: indicate when item in a list clicked? Pin
Richard MacCutchan30-Nov-19 4:37
mveRichard MacCutchan30-Nov-19 4:37 
AnswerRe: Javascript: indicate when item in a list clicked? Pin
Member 1469087415-Dec-19 23:21
Member 1469087415-Dec-19 23:21 
Questionre: Highlight all the fields Pin
Member 1466767925-Nov-19 5:27
Member 1466767925-Nov-19 5:27 
AnswerRe: re: Highlight all the fields Pin
jkirkerx25-Nov-19 8:11
professionaljkirkerx25-Nov-19 8:11 
GeneralRe: re: Highlight all the fields Pin
Member 1466767925-Nov-19 11:30
Member 1466767925-Nov-19 11:30 
GeneralRe: re: Highlight all the fields Pin
Member 1466767925-Nov-19 13:02
Member 1466767925-Nov-19 13:02 
QuestionJavaScript Question that doesn't make since. Pin
Member 1466141319-Nov-19 12:07
Member 1466141319-Nov-19 12:07 
AnswerRe: JavaScript Question that doesn't make since. Pin
Afzaal Ahmad Zeeshan19-Nov-19 16:58
professionalAfzaal Ahmad Zeeshan19-Nov-19 16:58 
QuestionHow can I avoid the phenomenon of asynchronous code using promises and async/await? Pin
Simos Sigma17-Nov-19 2:38
Simos Sigma17-Nov-19 2:38 
I am working on a cep html panels extension and I am facing this known "thorn" of asynchronous code!!! I know that the most secure way is to use promises and async/await, but my problem is that I can't really understand how I can suit my code to promises and async/await. I believe an example based on my code would really help me.

Here is a small example of my code...

JS FILE CODE:
JavaScript
(function()
{
    'use strict';
	
	const csInterface = new CSInterface();
	const extensionId =  csInterface.getExtensionID();
	let psDocumentsLength;
	
	function init()
	{
		themeManager.init();
	
		$(document).ready(function()
		{
			setTimeout(function(){check_PSDocumentsLength();
				setTimeout(function(){reclaim_PSDocumentsLength();
				}, 100);
			}, 100);
		});
	};
	
	function check_PSDocumentsLength()
	{
		var chosenFunction = 'checkDocumentsLength()';
		csInterface.evalScript(chosenFunction, function(result)
		{
			psDocumentsLength = result;
		});
	};
	
	function reclaim_PSDocumentsLength()
	{
		if(psDocumentsLength < 1)
		{
			alert('There is no opened document!!!');
			csInterface.closeExtension()
		};
	};
    
    init();
	
}());
JSX CODE:
JavaScript
function checkDocumentsLength()
{
	return documents.length;
};

As you can see, in order to avoid the phenomenon of asynchronous code, I am using nested setTimeout(s). Is there anyone who can explain to me how I can do the same thing but using promises and async/await?

Thank you in advance!!!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.