multithread trial 3
This commit is contained in:
parent
5ff6913426
commit
f587864d3c
3 changed files with 37 additions and 16 deletions
|
@ -2,24 +2,29 @@ import axios from "axios";
|
|||
|
||||
let shouldRun = false
|
||||
onmessage = (event) => {
|
||||
if (event.data === "start") {
|
||||
const { action, access_token } = event.data
|
||||
if (action === "start") {
|
||||
shouldRun = true
|
||||
fetchData()
|
||||
} else if (event.date === "terminate") {
|
||||
fetchData(access_token)
|
||||
} else if (action === "terminate") {
|
||||
shouldRun = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchData = () => {
|
||||
console.log('starting get loop');
|
||||
|
||||
const fetchData = (access_token) => {
|
||||
if (!shouldRun) return
|
||||
|
||||
const apiURL = "http://localhost:5000/interstellar/api/ai_get"
|
||||
|
||||
const apiURL = "http://localhost:5000/interstellar/api/ai_get?access_token="+access_token
|
||||
|
||||
axios.get(apiURL)
|
||||
.then(response => {
|
||||
const data = response.data.response
|
||||
const data = response.data
|
||||
console.log(data);
|
||||
postMessage(data)
|
||||
setTimeout(fetchData,500)
|
||||
setTimeout(fetchData,100)
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('Error fetching data:', error);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue