You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 17, 2023. It is now read-only.
return thunk function. You should run the thunk function because of thunk's lazy evaluation. If iter is infinite, you will not get the last result except error occured.
36
+
37
+
-`iter`: {Function}, it is your task loop, can be sync or async task. If `iter`'s result is `true`, the loop will continue, otherwise the loop will terminate.
38
+
39
+
**Sync function:**
40
+
```js
41
+
var i =1000
42
+
thunkLoop(function () {
43
+
if (--i) returntrue
44
+
return'OK'
45
+
})(function (err, res) {
46
+
console.log(err, res, i) // null, 'OK', 0
47
+
})
48
+
```
49
+
50
+
**Promise:**
51
+
```js
52
+
var i =1000
53
+
thunkLoop(function () {
54
+
if (--i) returnPromise.resolve(true)
55
+
returnPromise.resolve('OK')
56
+
})(function (err, res) {
57
+
console.log(err, res, i) // null, 'OK', 0
58
+
})
59
+
```
60
+
61
+
**Generator function:**
62
+
```js
63
+
var i =1000
64
+
thunkLoop(function*() {
65
+
// yield thunk or promise
66
+
if (--i) returnyieldthunk(true)
67
+
returnyieldPromise.resolve('OK')
68
+
})(function (err, res) {
69
+
console.log(err, res, i) // null, 'OK', 0
70
+
})
71
+
```
72
+
73
+
-`errorHandle`: {Function}, it is optional, can be sync or async function. It is used to catch the exception from `iter`.
74
+
75
+
If `errorHandle` omit. the exception from `iter` will terminate loop:
76
+
```js
77
+
thunkLoop(function*() {
78
+
thrownewError('error!')
79
+
})(function (err, res) {
80
+
console.log(err.message, ) 'error!'
81
+
})
82
+
```
83
+
84
+
If `errorHandle` return `true`. the exception from `iter` will ignore and loop will continue:
0 commit comments