n = array.length;
n = 1;
for(i=0; i<n; i++) {
x = array.charAt(i);
lookUp(x);
}
document.getElementById("input").value = document.getElementById("input").value.slice(1,1000);
Please help me @rfindley, or someone. I don’t know how to use Promise. Asynchronicity is a big problem. I can’t manage to delay function, while maintaining loop. I can still manage it semi-manually, while looking at the console, though.
Using For loop with HTML requests. It goes from fetchInfo(x[i]) to fetchInfo(x[i+1]) before HTML requests finishes, so I can’t just use the Loop with += fetchInfo(x[i]).
I’m still figuring out the code, so I might be shooting in the dark for a bit, but is there a reason one api call has to wait for the next? if the issue is the “i” variable, try adding “let” right before it:
for(let i=0; i<n; i++) { …
I don’t know how familiar you are with JS or ES6, but the let keyword is really useful for loops with asynchronicity
Well, it (mostly) works… I set it to wait 500ms between calls, but I think that’s still a little aggressive, I got 7/80 returns putting in all the joyo kanji at once. can probably add an error handler to re-do those calls later.
Promises aren’t really necessary, you just need to write all the code in the callback function, process_result. Calls don’t really need to wait for the previous ones to get back, either, though I added a setTimout so the server wouldn’t be flooded all at once if I enter a lot of Kanji.
Success. One button. Show something without a console, that is, show progress. setTimeout correctly is the key. I use 2000 milliseconds, though.
I might have to learn more about let, CodePen and GitHub. Also, I don’t know how to test something server related. This code doesn’t work on a outside server.
Sorry that my code isn’t clean and uses a bad convention.
///
Edit:
I have just understood about flooding the server, and waiting 200 msec. But, I might just wait for the next project to make a improvement, though. It is possible, but shouldn’t be done, to send all the Request (almost) simultaneously, isn’t it?
Still, I wait for an arbitrary amount of time, but I can’t really use the result immediately after the process in done? Any way to tell if the process is done or not done?
It’ll work without let, I think, since the outgoing call happens synchronously (even if the callback doesn’t) and it’s the only thing that directly depends on “i”. The server flood is more to stop 503 errors (server overload). I got less of them the more I waited between calls. The API is kind of slow.
As for telling when it’s complete, I had some code in mine that made a counter for when the calls came back to say when it was complete, but I wasn’t counting when it errored out, so it’s only accurate if there are no errors. It should be fairly straightforward to make a try-catch block to count if it errors out and maybe do the call again / advance the counter.