question

fakepl avatar image
fakepl asked

How to execute function after two requests are done?

Hello, I want to execute function after two requests are done. What's the best way to recognize both requests are done and how to call a function after this recognition? In code it looks like this:

public void ShowItems()<br>{
	PlayFabClientAPI.GetCatalogItems(request1, CISuccess, CIFailure);
	PlayFabClientAPI.GetUserReadOnlyData(request2, UDSuccess, UDFailure);<br>}

private void CISuccess(GetCatalogItemsResult result)<br>{
	//DO SOME STUFF BASED ON RESULT AND SAVE VALUES TO VARIABLE DATA1
	var DATA1;<br>}

private void UDSuccess(GetUserDataResult result)<br>{
	//DO SOME STUFF BASED ON RESULT AND SAVE VALUES TO VARIABLE DATA2
	var DATA2;<br>}

//CALL THIS WHEN BOTH REQUESTS ARE DONE
private void DrawItems()<br>{
	//DRAW ITEMS USING DATA1 AND DATA2 VALUES<br>}

I'm using Unity with C#. Thanks.

10 |1200

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

1 Answer

·
Joshua Strunk avatar image
Joshua Strunk answered

Two options.

1) Chain them so that one is called in the success callback of the other

2) Add some sort of counter or boolean you can flip and then check in each callback.

Both of these could be abstracted out nicely into function objects or through the use of lambda functions.

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.