Skip to content

outputJson does not preserve the object for asynchronous processing #702

@paragi

Description

@paragi
  • Operating System: Linux 4.15.0-52 Debian
  • Node.js version: 12.2.0
  • fs-extra version:8.1.0

When writing object asynchronously with outputJson, the object is not preserved, before the promise is returned.

Example:

const fs = require('fs-extra');

( async () => {
  let i;
  let obj = {}
  let promises = [];

  for( i = 0; i<4; i++ ){
    obj.id = i;
    promises.push( fs.outputJson('./' + i, obj) );
  }

  await Promise.all(promises);

  for( i = 0; i<4; i++ )
    console.log( await fs.readJson('./' + i));

})();

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions