Recursive table formulating function that waits for page to load before each step












0















I am trying to find out how to have all of these things in the same function:




  1. An array of objects where sections of it are generated through a time-consuming function

  2. The DOM loading before each attempt at loading the next section of array objects


I have tried Promise, recursive functions to my best ability, to no prevail.
Here is the code I am manipulating:



showLoader();

var preArray = new Array();
var subjects = scrapeSubjects();

function next(subject, prearray) {
if (subject.length) {
//Writes an element specifying the current section being loaded for the user on a loading page
writeToLoader(subject[0]);
$( document ).ready( function() { next(subject); });
prearray = prearray.concat(pullData(subject.shift()));
}
};
preArray = next(subjects, preArray);

var array = stripNonRooms(preArray, roomsArray);
localStorage.setItem('data', JSON.stringify(array));
//hides the loader when it is complete
var loader = document.getElementById("loader");
loader.style.display = "none";


Is there anything I can do to show the user the section that is currently being loaded, while it is being loaded?










share|improve this question























  • Where are the promises in your code? Which part is actually asynchronous?

    – Bergi
    Nov 25 '18 at 12:13











  • @Bergi can I not just use some sort of wait function before continuing my code?

    – tincopper2
    Nov 27 '18 at 1:22











  • No, you will need to use a specific wait function, and if you want to wait for something it'll be asychronous. But what in your code snippet above do you want to wait for?

    – Bergi
    Nov 27 '18 at 8:00











  • @Bergi page ready, I have it specified, I only want to update a doc as I am running my code, so the user can see the div update as the code is running

    – tincopper2
    Nov 28 '18 at 14:25











  • The document does get ready only once. If you change something, that doesn't "un-ready" the page. If your problem is long-running code and the browser doesn't render your change soon enough, the only thing you can do is to make it asynchronous with a little timeout.

    – Bergi
    Nov 28 '18 at 14:40
















0















I am trying to find out how to have all of these things in the same function:




  1. An array of objects where sections of it are generated through a time-consuming function

  2. The DOM loading before each attempt at loading the next section of array objects


I have tried Promise, recursive functions to my best ability, to no prevail.
Here is the code I am manipulating:



showLoader();

var preArray = new Array();
var subjects = scrapeSubjects();

function next(subject, prearray) {
if (subject.length) {
//Writes an element specifying the current section being loaded for the user on a loading page
writeToLoader(subject[0]);
$( document ).ready( function() { next(subject); });
prearray = prearray.concat(pullData(subject.shift()));
}
};
preArray = next(subjects, preArray);

var array = stripNonRooms(preArray, roomsArray);
localStorage.setItem('data', JSON.stringify(array));
//hides the loader when it is complete
var loader = document.getElementById("loader");
loader.style.display = "none";


Is there anything I can do to show the user the section that is currently being loaded, while it is being loaded?










share|improve this question























  • Where are the promises in your code? Which part is actually asynchronous?

    – Bergi
    Nov 25 '18 at 12:13











  • @Bergi can I not just use some sort of wait function before continuing my code?

    – tincopper2
    Nov 27 '18 at 1:22











  • No, you will need to use a specific wait function, and if you want to wait for something it'll be asychronous. But what in your code snippet above do you want to wait for?

    – Bergi
    Nov 27 '18 at 8:00











  • @Bergi page ready, I have it specified, I only want to update a doc as I am running my code, so the user can see the div update as the code is running

    – tincopper2
    Nov 28 '18 at 14:25











  • The document does get ready only once. If you change something, that doesn't "un-ready" the page. If your problem is long-running code and the browser doesn't render your change soon enough, the only thing you can do is to make it asynchronous with a little timeout.

    – Bergi
    Nov 28 '18 at 14:40














0












0








0








I am trying to find out how to have all of these things in the same function:




  1. An array of objects where sections of it are generated through a time-consuming function

  2. The DOM loading before each attempt at loading the next section of array objects


I have tried Promise, recursive functions to my best ability, to no prevail.
Here is the code I am manipulating:



showLoader();

var preArray = new Array();
var subjects = scrapeSubjects();

function next(subject, prearray) {
if (subject.length) {
//Writes an element specifying the current section being loaded for the user on a loading page
writeToLoader(subject[0]);
$( document ).ready( function() { next(subject); });
prearray = prearray.concat(pullData(subject.shift()));
}
};
preArray = next(subjects, preArray);

var array = stripNonRooms(preArray, roomsArray);
localStorage.setItem('data', JSON.stringify(array));
//hides the loader when it is complete
var loader = document.getElementById("loader");
loader.style.display = "none";


Is there anything I can do to show the user the section that is currently being loaded, while it is being loaded?










share|improve this question














I am trying to find out how to have all of these things in the same function:




  1. An array of objects where sections of it are generated through a time-consuming function

  2. The DOM loading before each attempt at loading the next section of array objects


I have tried Promise, recursive functions to my best ability, to no prevail.
Here is the code I am manipulating:



showLoader();

var preArray = new Array();
var subjects = scrapeSubjects();

function next(subject, prearray) {
if (subject.length) {
//Writes an element specifying the current section being loaded for the user on a loading page
writeToLoader(subject[0]);
$( document ).ready( function() { next(subject); });
prearray = prearray.concat(pullData(subject.shift()));
}
};
preArray = next(subjects, preArray);

var array = stripNonRooms(preArray, roomsArray);
localStorage.setItem('data', JSON.stringify(array));
//hides the loader when it is complete
var loader = document.getElementById("loader");
loader.style.display = "none";


Is there anything I can do to show the user the section that is currently being loaded, while it is being loaded?







javascript jquery arrays async-await






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 7:24









tincopper2tincopper2

449




449













  • Where are the promises in your code? Which part is actually asynchronous?

    – Bergi
    Nov 25 '18 at 12:13











  • @Bergi can I not just use some sort of wait function before continuing my code?

    – tincopper2
    Nov 27 '18 at 1:22











  • No, you will need to use a specific wait function, and if you want to wait for something it'll be asychronous. But what in your code snippet above do you want to wait for?

    – Bergi
    Nov 27 '18 at 8:00











  • @Bergi page ready, I have it specified, I only want to update a doc as I am running my code, so the user can see the div update as the code is running

    – tincopper2
    Nov 28 '18 at 14:25











  • The document does get ready only once. If you change something, that doesn't "un-ready" the page. If your problem is long-running code and the browser doesn't render your change soon enough, the only thing you can do is to make it asynchronous with a little timeout.

    – Bergi
    Nov 28 '18 at 14:40



















  • Where are the promises in your code? Which part is actually asynchronous?

    – Bergi
    Nov 25 '18 at 12:13











  • @Bergi can I not just use some sort of wait function before continuing my code?

    – tincopper2
    Nov 27 '18 at 1:22











  • No, you will need to use a specific wait function, and if you want to wait for something it'll be asychronous. But what in your code snippet above do you want to wait for?

    – Bergi
    Nov 27 '18 at 8:00











  • @Bergi page ready, I have it specified, I only want to update a doc as I am running my code, so the user can see the div update as the code is running

    – tincopper2
    Nov 28 '18 at 14:25











  • The document does get ready only once. If you change something, that doesn't "un-ready" the page. If your problem is long-running code and the browser doesn't render your change soon enough, the only thing you can do is to make it asynchronous with a little timeout.

    – Bergi
    Nov 28 '18 at 14:40

















Where are the promises in your code? Which part is actually asynchronous?

– Bergi
Nov 25 '18 at 12:13





Where are the promises in your code? Which part is actually asynchronous?

– Bergi
Nov 25 '18 at 12:13













@Bergi can I not just use some sort of wait function before continuing my code?

– tincopper2
Nov 27 '18 at 1:22





@Bergi can I not just use some sort of wait function before continuing my code?

– tincopper2
Nov 27 '18 at 1:22













No, you will need to use a specific wait function, and if you want to wait for something it'll be asychronous. But what in your code snippet above do you want to wait for?

– Bergi
Nov 27 '18 at 8:00





No, you will need to use a specific wait function, and if you want to wait for something it'll be asychronous. But what in your code snippet above do you want to wait for?

– Bergi
Nov 27 '18 at 8:00













@Bergi page ready, I have it specified, I only want to update a doc as I am running my code, so the user can see the div update as the code is running

– tincopper2
Nov 28 '18 at 14:25





@Bergi page ready, I have it specified, I only want to update a doc as I am running my code, so the user can see the div update as the code is running

– tincopper2
Nov 28 '18 at 14:25













The document does get ready only once. If you change something, that doesn't "un-ready" the page. If your problem is long-running code and the browser doesn't render your change soon enough, the only thing you can do is to make it asynchronous with a little timeout.

– Bergi
Nov 28 '18 at 14:40





The document does get ready only once. If you change something, that doesn't "un-ready" the page. If your problem is long-running code and the browser doesn't render your change soon enough, the only thing you can do is to make it asynchronous with a little timeout.

– Bergi
Nov 28 '18 at 14:40












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465483%2frecursive-table-formulating-function-that-waits-for-page-to-load-before-each-ste%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465483%2frecursive-table-formulating-function-that-waits-for-page-to-load-before-each-ste%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python