最后一个链式承诺没有运行 [英] The last chained promise does not run

查看:26
本文介绍了最后一个链式承诺没有运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经链接了一些我想按特定顺序执行的方法.第二个方法 deviseLogin() 返回一个 URL,该 URL 应该传递给下一个方法 redirect(url)

I have chained a few methods that I'd like to execute in that specific order. The second method deviseLogin() returns a URL that should be passed on the the next method redirect(url)

第一个和第二个方法运行,但我从来没有听到最后一个redirect(url)的任何消息.你能看出我做错了什么吗?

The first and the second method runs, but I never hear anything from the last redirect(url). Can you see what I'm doing wrong?

  getUserToken = (username, password) ->
    console.log "I'm first"
    $http(
      method: "POST"
      url: "/oauth/token"
      params: params
    ).success((data, status, headers, config) ->
      $scope.$storage.token = data.access_token   


  defer = $q.defer()

  $scope.signIn = (data) ->
    defer.promise
      .then( getUserToken($scope.email, $scope.password) )
      .then( deviseLogin() )
      .then( redirect(url) )


  redirect = (url) ->
    console.log "I'm last"
    console.log "will redirect to #{url}"
    $window.location = data.url

  deviseLogin = () ->
    console.log "I'm second"
    $scope.authErrors = []
    authData = { user: { email: $scope.email, password: $scope.password }}
    $http(
      # Perform a regular Devise login
      method: "POST"
      url: "/users/sign_in"
      data: authData
    )
    .success (data) ->
      # I can see the log lines below and data.url is what I expect it to be
      console.log "logged in devise"
      console.log "data.url: #{data.url}"
      data.url

推荐答案

I never got the last .then( redirect(url) ) 启动.通过移动 redirect 解决了问题(url)deviseLogin() 上的 success() 内.

I never got the last .then( redirect(url) ) to kick in. Solved the problem by moving redirect(url) to within success() on deviseLogin().

感谢所有的建议和帮助!:)

Thanks for all the suggestions and help! :)

这篇关于最后一个链式承诺没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆