Is there a good way to consolidate callbacks?

0 votes

I got a unique callback for each userservice: e.g.

userService.GetAllUsers( new GetAllUsersCallBack() );
userService.DeleteUserapp42userNamenew deleteUsersCallBack() );
userService.Authenticate( userNameOrEmailInput , pwdInput, new UserAuthorization() );
userService.ResetUserPassword( app42userName, new UserPwdReset() );
userService.UpdateEmail( app42userName, emailId, new UserEmailChange() );

I know the userService callback is the same standard format for whatever userService call is made BUT is it possible to have only one callback and in that callback a way to tell which userService caused the callback to be called? Then I could use a switch statement to make my one callback do the proper and corresponding jobs depending on which userService I used.

asked Jul 2, 2014 in App42 Cloud API-BaaS by huffman (17 points)

1 Answer

0 votes
Hi Huffman,
If you want to use these methods in single callback, You can set global variable for each method call like this.
e.g  bool getAllUsers = false, deleteUser = false; //etc
And when your method is called you must set this variable to true. e.g getAllUsers  = true;
finally do something like that in your callback.
public class UnityCallBack : App42CallBack
public void OnSuccess(object response)
 if(getAllUsers )
  IList<User> users = (IList<User>) response;
  //do your code 
 }else if(deleteUser)
  User user = (User) response;   
  // do your code 
 getAllUsers = false;
 deleteUser = false;
public void OnException(Exception e)
App42Log.Console("Exception : " + e);
answered Jul 2, 2014 by sshukla480 (407 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on