Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetSync don't work #19

Open
miltonmagalhaes opened this issue Jan 12, 2015 · 1 comment
Open

SetSync don't work #19

miltonmagalhaes opened this issue Jan 12, 2015 · 1 comment

Comments

@miltonmagalhaes
Copy link

The code run like
Step 1 -> Step 3 -> Step 2

I need to know the TypeArq content after reading the file, ie synchronous manner.
However, the contents of TypeArq return anything.

The Code:
var TypeArq = ""
alert("Step 1");
FileReaderJS.setSync(true);
FileReaderJS.setupInput(document.getElementById('input'), {
readAsDefault: "Text",
on: {
load: function(e, file) {
TypeArq = e.target.result.substring(1,8);
console.log("Funcionou--->" + e.target.result.substring(1,8));
alert("Step 2");
}
}
});
alert("Step 3");
alert(TypeArq)

@bgrins
Copy link
Owner

bgrins commented Jan 12, 2015

It's synchronous once the user begins the input (not on initialization). So there is an async gap between the code that sets up the reader and the user actually selecting a file. You can read more about this FileReaderSync object on MDN.

In your case, you could move 'step 3' and any logic within it into the load event and things would execute in the order you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants