question

se avatar image
se asked

Promises (async/await) in CloudScript javascript

Is it possible to use javascript Promises in the handlers for cloud script? I could not find any documentaion on this, and my preliminary experiments indicates that it does not work.

Trivial Example:

I would really like to do something like this:

handlers.someHandler = function (args, context) {
	return Promise.resolve({a: {myResponse: 'hello world'}})
	.then(result => {
		return result.a	})
}

Or even nicer:

handlers.someHandler = async function (args, context) {
	let result = await Promise.resolve({a: {myResponse: 'hello world'}})
	return result.a
}


Of course, my use-case is a bit more complex than the trivial examples above.

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image
Citrus Yan answered

You may use the new CloudScript using Azure Functions feature to write asynchronous code.

In addition to asynchronous programming, there are few other improvements:

  1. Ability to write Cloudscript in C# as well as Javascript and the other supported Azure Functions languages
  2. Ability to locally debug Cloudscript using Visual Studio or Visual Studio Code. In addition, we have released an open sourced Visual Studio Code Extension for PlayFab that makes it easier to create CloudScript using Azure Functions.
  3. No limits to the number of API calls within the Azure Function code.

Please navigate to the link to learn more: https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Denzie Gray avatar image Denzie Gray commented ·

@Citrus Yan

I am attempting something similar to the other user, are Promises and "await" supported?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Denzie Gray commented ·
0 Likes 0 ·
Em Lazer-Walker avatar image
Em Lazer-Walker answered

I'm not sure about the older CloudScript system, but this is definitely supported if you switch over to using the new version of CloudScript that uses Azure Functions: https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/quickstart

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.