ywana-core8 0.0.998 → 0.1.0
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/dist/index.cjs +40 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.modern.js +40 -9
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +40 -9
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/incubator/task.js +19 -7
package/package.json
CHANGED
package/src/incubator/task.js
CHANGED
@@ -13,7 +13,7 @@ export const TaskContext = React.createContext({})
|
|
13
13
|
*/
|
14
14
|
export const TaskContextProvider = (props) => {
|
15
15
|
|
16
|
-
const { host, url = "/tasks", frequency = 1000, children, ctx } = props
|
16
|
+
const { host, url = "/tasks", frequency = 1000, children, ctx, concurrent = false } = props
|
17
17
|
const API = CollectionAPI(url, host, "")
|
18
18
|
const [listeners, setListeners] = useState({})
|
19
19
|
const appContext = useContext(ctx)
|
@@ -26,7 +26,11 @@ export const TaskContextProvider = (props) => {
|
|
26
26
|
useEffect(() => {
|
27
27
|
if (Object.keys(listeners).length === 0) return
|
28
28
|
const _interval = setInterval(async () => {
|
29
|
-
|
29
|
+
if (concurrent) {
|
30
|
+
await concurrentExecuteListeners()
|
31
|
+
} else {
|
32
|
+
await executeListeners()
|
33
|
+
}
|
30
34
|
}, frequency)
|
31
35
|
return () => clearInterval(_interval)
|
32
36
|
}, [listeners])
|
@@ -41,6 +45,16 @@ export const TaskContextProvider = (props) => {
|
|
41
45
|
}
|
42
46
|
}
|
43
47
|
|
48
|
+
async function concurrentExecuteListeners() {
|
49
|
+
const taskIDs = Object.keys(listeners);
|
50
|
+
const taskPromises = taskIDs.map(taskID => context.task(taskID).then(tsk => [tsk, taskID]));
|
51
|
+
const tasks = await Promise.all(taskPromises);
|
52
|
+
tasks.forEach(([tsk, taskID]) => {
|
53
|
+
const listener = listeners[taskID];
|
54
|
+
if (listener) listener(tsk, appContextRef.current);
|
55
|
+
});
|
56
|
+
}
|
57
|
+
|
44
58
|
async function tasks(filters, likes) {
|
45
59
|
try {
|
46
60
|
const response = await API.all(filters, likes);
|
@@ -152,9 +166,9 @@ export const TaskProgress = (props) => {
|
|
152
166
|
|
153
167
|
async function refresh(id) {
|
154
168
|
const next = await context.task(id)
|
155
|
-
|
156
|
-
|
157
|
-
if (onComplete) onComplete(next)
|
169
|
+
if (next) {
|
170
|
+
setProgress(next.percentage)
|
171
|
+
if (next.percentage === 100 && onComplete) onComplete(next)
|
158
172
|
}
|
159
173
|
}
|
160
174
|
|
@@ -204,14 +218,12 @@ export const TaskMonitor = (props) => {
|
|
204
218
|
{ id: "actions", label: "" }
|
205
219
|
],
|
206
220
|
rows: tasks
|
207
|
-
|
208
221
|
// sort by init date from recent to old
|
209
222
|
.sort((a, b) => {
|
210
223
|
if (a.init > b.init) return -1
|
211
224
|
if (a.init < b.init) return 1
|
212
225
|
return 0
|
213
226
|
})
|
214
|
-
|
215
227
|
.map(task => {
|
216
228
|
return {
|
217
229
|
id: task.id,
|