zoukankan      html  css  js  c++  java
  • 同步等待方法

    function waitVar(key,varb, fun) {      //等待指定变量,返回:-1:无数据,继续等待 -2:超时 1:成功。fun不支持参数
      if (!cnt2[key]) {
        cnt2[key] = 1
      }
      else {
        cnt2[key]++
      }
      if (!varb || varb.length == 0) {
        if (cnt2[key] > 10) {      //超时,由于都是异步操作,相互依赖的变量会同时判断,所以这个时间是最大的
          wx.showToast({
            title: '无法获取数据!',
            image: "/remind.png",
            duration: 3000
          })
          return -2
        }
        else {
          console.log("等待变量同步" + key, varb)
          wx.showToast({
            title: '正在下载数据!',
            image: "/remind.png",
            duration: 500
          })
    
          if (arguments.length == 3)  //正常状态,fun没有参数
            setTimeout(fun, 500)
    
          //对于onLoad无法使用,因为他的参数无法像普通参数一样处理  
          if (arguments.length == 4)  //正常状态,fun有1个参数,arguments不能按照数组来处理,不能用slice,所以逐个处理
          {
            console.log("参数",arguments,arguments[3])
            setTimeout(fun, 500, arguments[3]) //arguments:0,1,2:3个参数。3:传递给fun的参数。setTimeout(回调函数,时间,参数1,...,参数n)
          }
    
          return -1
        }
      }
      return 1
    }
  • 相关阅读:
    Linux Commands
    sizeof操作符的使用详解
    在Vim中使用cscope
    MySQL学习笔记
    Online judge for leetcode
    使用Vim,让你工作效率更高
    Ext JS笔记
    安装J2EE开发环境
    这些都是什么啊
    QrCode二维码的实现原理
  • 原文地址:https://www.cnblogs.com/jetz/p/7746120.html
Copyright © 2011-2022 走看看