Fórum

How to make Liferay.Service from asynchronous to synchronous

thumbnail
saleem khan, modificado 9 Anos atrás.

How to make Liferay.Service from asynchronous to synchronous

Junior Member Postagens: 71 Data de Entrada: 16/11/13 Postagens Recentes
Hi....
I want to make Liferay.Services to synchronous from asynchronous can any help me in this and tell how to do it,
Sameer Naik, modificado 8 Anos atrás.

RE: How to make Liferay.Service from asynchronous to synchronous

Junior Member Postagens: 25 Data de Entrada: 09/03/10 Postagens Recentes
Did you get any solution for this?
thumbnail
Prakash Khanchandani, modificado 8 Anos atrás.

RE: How to make Liferay.Service from asynchronous to synchronous

Expert Postagens: 329 Data de Entrada: 10/02/11 Postagens Recentes
I don't think there are any attributes to do this, but you might be able to make it synchronous by modifying /portal-web/docroot/html/js/liferay/liferay.js file through a hook.

This is the file which actually creates this Service module which is then used by other plugins. You might add an option to make it synchronous, since it uses io-request module what you can do is make use of the sync attribute of this module which makes the request synchronous when the value is true by default the value is false.

So you can dd an attribute to Service module like serviceSync which when true would make the call Synchronous and false is the default value. You can pass this value to the code which uses the aui-io-request module in this file:

Liferay.provide(
		Service,
		'invoke',
		function(payload, ioConfig) {
			var instance = this;

			A.io.request(
				instance.URL_INVOKE,
				A.merge(
					{
						data: {
							cmd: A.JSON.stringify(payload),
							p_auth: Liferay.authToken
						},
						dataType: 'json'
					},
					ioConfig
				),
                               sync: serviceSync // this is where you could use it
			);
		},
		['aui-io-request']
	);


I have not tried it but I would think this would work if done correctly.
Hope this gives some head-start.
Sameer Naik, modificado 8 Anos atrás.

RE: How to make Liferay.Service from asynchronous to synchronous

Junior Member Postagens: 25 Data de Entrada: 09/03/10 Postagens Recentes
Thanks Prakash for your detailed response. On second thought, we are planning to leave it the asynchronous way.
Making it synchronous will block entire browser when the request does not complete in timely manner.

We found this from Nate.
https://gist.github.com/natecavanaugh/5222770
Says "Not Recommended" in the title.

I believe this was synchronous in 6.1

-- Sameer
thumbnail
Prakash Khanchandani, modificado 8 Anos atrás.

RE: How to make Liferay.Service from asynchronous to synchronous

Expert Postagens: 329 Data de Entrada: 10/02/11 Postagens Recentes
Yup Asynchronous is the best bet emoticon
thumbnail
Allen Ziegenfus, modificado 6 Anos atrás.

RE: How to make Liferay.Service from asynchronous to synchronous

New Member Postagens: 11 Data de Entrada: 29/12/15 Postagens Recentes
It's also possible like this:

Liferay.Service(
	{
		'/mbcategory/get-categories':
		{
			groupId: themeDisplay.getScopeGroupId(),
			parentCategoryId: 0,
			status: 0,
			start: -1,
			end: -1
		},
		io: { 
				on: {
					failure: function(event, id, obj) {
						msg.setContent(
							'<div class="portlet-msg-error">' +
								'${localize("your_request_failed_to_complete", "Your Request Failed to Complete")}' +
							'</div>'
						);
					},
					success:function() { } 
				},
			sync: true
		}
	}
);