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

setTimeOut 偶现不执行 #19

Open
iShawnWang opened this issue Dec 20, 2017 · 4 comments
Open

setTimeOut 偶现不执行 #19

iShawnWang opened this issue Dec 20, 2017 · 4 comments
Projects

Comments

@iShawnWang
Copy link

iShawnWang commented Dec 20, 2017

发现的问题

  • 正常情况下写 setTimeOut 方法, 隔 500ms 执行一个函数, 打印log 一切正常
  • 特殊情况下, 该函数不执行, 然后当你滑动一个页面, 点击一个按钮, 或者轮播图自动滚动之后, 该函数就执行了.

我的猜想和推理

  1. 有事件发生后, setTimeOut 的函数才执行.
  2. 平时执行 js 的线程的 runloop 是停止的 ? 这个和 WKWebView 背后调度执行 js 的 engine 的实现有很大关系

相关的情况

  1. 首先 : Safari 真机调试js
  2. 运行转换后的小程序 app 在 iOS 真机 上, 按如下图 inspect 小程序的页面,

4171513321661_ pic_hd

Inspect 界面出来后, 菊花会一直转, 此时你手动点击按钮或者 push 新界面, 这个菊花就停止转了, 一切正常了, (我的情况是 : 主页面有轮播图, 轮播图自动轮播事件触发后, 一切正常了)

4241513321759_ pic_hd

具体情况可以联系 @me & @IOriens

Update

找到了暂时的 polyfill : native 注入 setTimeOut 方法, 用 dispatch_after 实现

@wwwyiqiao
Copy link
Contributor

wwwyiqiao commented Dec 21, 2017

我之前也猜想过是runloop的原因 还没找到解决方案 下面的代码暂时解决setTimeOut的问题

          var now = new Date();
           var exitTime = now.getTime() + number;
           while (true) {
               now = new Date();
               if (now.getTime() > exitTime)
                   break;
           }

我试试上面native注入setTimeOut的方式

@iShawnWang
Copy link
Author

我自己尝试 Google 过, 全是讲 WKWebView 的 API 相关的东西, 暂时还没什么头绪...

@IOriens IOriens added this to To Do in Schedule Dec 25, 2017
IOriens added a commit that referenced this issue Dec 25, 2017
@gordanyang
Copy link

提交了一个PR,#40 不知有没有帮助。

@IOriens
Copy link
Contributor

IOriens commented Aug 24, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Schedule
  
Common-ToDo
Development

No branches or pull requests

4 participants