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

write() resolves before content is written #149

Closed
nknapp opened this issue Oct 5, 2015 · 5 comments · Fixed by #153
Closed

write() resolves before content is written #149

nknapp opened this issue Oct 5, 2015 · 5 comments · Fixed by #153

Comments

@nknapp
Copy link

nknapp commented Oct 5, 2015

The following code-snippets seems not to work as expected in node 4.1:

var qfs = require('q-io/fs')
var fs = require('fs')

qfs.write('abc.txt', 'this is the file contents')
  // .delay(1000)
  .done(function () {
    console.log(fs.readFileSync('abc.txt', { encoding: 'utf-8'}))
  })

In nodejs 0.10.38, this outputs the line this is the file contents, in node 4.1.0, I only get an empty line in the output. It seems like the promise is resolved before the contents is written. Removing the comment in front of the .delay(1000) causes the correct line to appear.

@nknapp
Copy link
Author

nknapp commented Oct 5, 2015

Using the read() function of q-io/fs also prints the correct line:

var qfs = require('q-io/fs')
qfs.write('abc.txt', 'this is the file contents')
  // .delay(1000)
  .done(function () {
    qfs.read('abc.txt').done(console.log)
  })

@kriskowal
Copy link
Owner

Thanks. A PR would be most welcome.

@nknapp
Copy link
Author

nknapp commented Oct 5, 2015

Where is the write()-method defined? Shouldn't it be in fs.js somewhere?

@kriskowal
Copy link
Owner

Methods of streams are in one of the stream modules, and in particular interest for these purposes, the Node bindings for streams. I don’t recall the specific module off-hand. I may be of more assistance after business hours.

@gagern
Copy link
Collaborator

gagern commented Dec 1, 2015

It isn't write which is broken, it's close which incorrectly assumes that we don't have a finish event, due to a broken version comparison.

This was referenced Jul 22, 2016
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

Successfully merging a pull request may close this issue.

3 participants