cbvirtua 1.0.52 → 1.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbvirtua",
3
- "version": "1.0.52",
3
+ "version": "1.0.53",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -50,4 +50,34 @@ function createHDCanvas (canvas, w, h) {
50
50
  作者:李彦辉Jacky
51
51
  链接:https://juejin.cn/post/7014765000916992036
52
52
  来源:稀土掘金
53
+ 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
54
+
55
+ const TTL = 5 * 1000 * 1000
56
+ const startTime = new Date().getTime()
57
+ async function polling() {
58
+
59
+ // 超过存活时间结束
60
+ const endTime = new Date().getTime()
61
+ if (endTime - startTime > TTL) {
62
+ return
63
+ }
64
+
65
+ // 这里的remoteCall是一个虚拟的函数,指代需要轮询的http接口
66
+ const response = await remoteCall()
67
+
68
+ // 这里的状态可以基于http,也可以自己定义自己的结构来处理。这里用200和非200做一个事例
69
+ if (response.status === 200) {
70
+ return response
71
+ } else {
72
+ // 这里可以看情况设定一个间隔时间。
73
+ // 复杂一点的可以设定一些间隔时间策略: 比如根据请求次数增加,增加间隔时间等等
74
+ // 这里只是一个例子,等待5秒
75
+ await new Promise(resolve => setTimeout(resolve, 5000));
76
+ return await polling()
77
+ }
78
+ }
79
+
80
+ 作者:小南聊一聊
81
+ 链接:https://juejin.cn/post/7099252918682910733
82
+ 来源:稀土掘金
53
83
  著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。