コード例 #1
0
    private Promise <string> AuthPromiseChaining()
    {
        var authModel = new Auth {
            Username = "******", Password = "******"
        };

        return(_userDataService.Auth(authModel)
               .Then(authResponse => _userDataService.Get(authResponse.UserId))
               .Then(user => user.Level)
               .Then(x => Debug.Log(string.Format("PromiseHttpController.OnGUI - [Thenx3] User Complete - LoadLevel={0}", x)))
               .Fail(x => Debug.LogError("An error has occoured.")));

        //NOTE: Instead of the above you can write it as below as well.

        //return _userDataService.Auth(authModel)
        //			.Then(delegate(AuthResponse authResponse)
        //				{
        //					Debug.Log(string.Format("PromiseHttpController.OnGUI - [Then] authResponse={0}", authResponse));
        //					return _userDataService.Get(authResponse.UserId);
        //				})
        //			.Then(delegate(User user)
        //				{
        //					Debug.Log(string.Format("PromiseHttpController.OnGUI - [Thenx2] User Result. user={0}", user));
        //					return user.Level;
        //				})
        //			.Then(delegate(string level)
        //				  {
        //					  Debug.Log(string.Format("PromiseHttpController.OnGUI - [Thenx3] User Complete - LoadLevel={0}", level));
        //					  //TODO. LoadLevel...
        //				  })
        //			.Fail(x => Debug.LogError("An error has occoured."));
    }