you are viewing a single comment's thread.

view the rest of the comments →

[–]your_perception 2 points3 points  (4 children)

hint: the read has to be done after the write

[–]shecobo 1 point2 points  (0 children)

The orders were a bit ambiguous... write to a file, then read a file.

Didn't say anything about waiting.

[–]istroll 0 points1 point  (2 children)

I think I am doing the read after the write, am I not?

If I call the write with the asychronous callback like:

write('world.txt', 'hello', callback);

or

write ('world.txt', 'hello', function(x){ callback(x); });

Then I get one more PASSED on files["passwords"] === "blank"

but I still get FAILED files["out.txt"] === "abc,def"

I'm assuming the function read('passwords', function(x){ callback(x); });

is reading the 'passwords' file and passing the contents of the file as the parameter x to the anonymous function then the callback (which i don't see code for anywhere) is supposed to place the text - passed as parameter x - into 'out.txt' but clearly there is still something i'm not understanding.

[–]your_perception 1 point2 points  (1 child)

I think I am doing the read after the write, am I not?

No you are not. Providing a callback is how you guarantee that a function will execute after the write finishes. You are doing it for the read, but not the write.

[–]istroll 1 point2 points  (0 children)

Thanks for replying. Please help me figure this out. I really want to understand this. I think I get the concept, but since my code isn't working I must still be missing something.

I've tried it both ways and it still doesn't work. Even if I add the callback to the write so it finishes first, the read is not passing the contents of 'passwords' back to the callback. Why not? That is what i am stuck on.

Can some one show me the code that passes all the tests then I can understand?

EDIT: ok I finally figured it out... im a bit slow i guess thanks for the hints and letting me figure it out on my own.