Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对Taro.requestPayment 使用await/async 时,添加Taro.requestPayment的回调函数后代码不会停止运行 #10589

Closed
hyisfine opened this issue Nov 4, 2021 · 1 comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@hyisfine
Copy link

hyisfine commented Nov 4, 2021

相关平台

微信小程序

小程序基础库: 2.20.1
使用框架: React

复现步骤

(async ()=>{
await Taro.requestPayment({ ...props,fail: () => {}})
console.log('await/async not working!')
})()

期望结果

期待代码可以停止等待支付完成

实际结果

调起了支付,但是代码会继续往后执行

环境信息

 Taro v3.3.12


  Taro CLI 3.3.12 environment info:
    System:
      OS: macOS 10.14.6
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 12.18.3 - /usr/local/bin/node
      npm: 6.14.6 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.3.12 => 3.3.12 
      @tarojs/components: 3.3.12 => 3.3.12 
      @tarojs/mini-runner: 3.3.12 => 3.3.12 
      @tarojs/react: 3.3.12 => 3.3.12 
      @tarojs/runtime: 3.3.12 => 3.3.12 
      @tarojs/taro: ^3.3.12 => 3.3.12 
      @tarojs/webpack-runner: 3.3.12 => 3.3.12 
      babel-preset-taro: 3.3.12 => 3.3.12 
      eslint-config-taro: 3.3.12 => 3.3.12 
      react: ^17.0.2 => 17.0.2 
      taro-ui: ^3.0.0-alpha.10 => 3.0.0-alpha.10 
    npmGlobalPackages:
      typescript: 4.4.0-dev.20210702
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Nov 4, 2021
@Chen-jj
Copy link
Contributor

Chen-jj commented Nov 23, 2021

@hyisfine 这个 API 在微信文档里标注了支持 Promise 调用的,对于此类 API,Taro 不会做额外操作,都是直接调用小程序底层 API。

image

因此,你测试到的结果是微信小程序的标准表现。也就是说,当传入了回调函数,此 API 就不支持 Promise 调用了。如果你要用 Promise 形式,就不要传回调函数,而是使用 try catch 捕捉错误。

@Chen-jj Chen-jj closed this as completed Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants