Coder Social home page Coder Social logo

Corruption & Async about node-json-db HOT 1 CLOSED

belphemur avatar belphemur commented on July 19, 2024
Corruption & Async

from node-json-db.

Comments (1)

Belphemur avatar Belphemur commented on July 19, 2024

Hello @rknell,

Well I chose Sync I/O for multiple reason. I didn't want to juggle with different Promise when doing a push + save on disk. I discover that with the Async IO if not used properly with callback or Promise you corrupt directly the file on which you write (since there is no locking of the file and the write all write together).

For the sake of simplicity and readability I gave up on Async and went full sync. Sure there is a downside in performance, this is why I added the possibility to not save on the file at each push but when the user decides (leading to a possible loss of data in case of power loss).

If you want to go for Async I/O, I'll advise to use a lock like this lib: https://www.npmjs.com/package/rwlock
to be able to block access to the file and do one writing at a time.

from node-json-db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.