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

[v2] Last written file is always empty #157

Open
dogancelik opened this issue Aug 10, 2016 · 1 comment
Open

[v2] Last written file is always empty #157

dogancelik opened this issue Aug 10, 2016 · 1 comment

Comments

@dogancelik
Copy link

dogancelik commented Aug 10, 2016

I have a Promise chain like this:

var q = require('q');
var fs = require("q-io/fs");

function save(filename, data) {
  return fs.write(filename, JSON.stringify(data, null, 2));
}

downloadAll.then(function () {
  var saves = [];
  // emotes is a global variable, has 10.000 objects
  saves.push(save('hello.json', { data: "hello" }));
  Object.keys(emotes).forEach(function (key) {
    saves.push(save(`${emotes[key].name}.json`, emotes[key]));
  });
  saves.push(save('bye.json', { data: "bye" }));
  return q.all(saves);
})
.then(function () {
  console.log('All files are saved');
});

bye.json is always empty, there is no data written.
If you switch places of hello.json and bye.json, this time hello.json becomes empty.

q version: ^1.4.1
q-io version: kriskowal/q-io#v2

@dogancelik
Copy link
Author

Here's a temporary solution using module graceful-fs:

var fs = require('graceful-fs')
var q = require('q');
var writeFile = q.nfbind(fs.writeFile);

function save(filename, data) {
  return writeFile(filename, JSON.stringify(data, null, 2));
}

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

1 participant