Arc Forumnew | comments | leaders | submitlogin
2 points by palsecam 5481 days ago | link | parent

Improved version with a 'smarter-save-table. I changed the name of 'ptable to 'db in reference to the first drafts of Arc + it's short + I like it.

  (= buffered-execs* (table))

  (def buffer-exec (f (o delay 1))
    (unless buffered-execs*.f
      (= buffered-execs*.f 
         (thread (sleep delay) (wipe buffered-execs*.f) (f)))))

  (= dbs* ())

  (def db (fname (o delay 0.5))  ; file "synced" every 0.5 sec
    (withs (tbl (safe-load-table fname)
    	    savefn (fn () (atomic:save-table tbl fname)))
      (push (list tbl (fn () (buffer-exec savefn delay))) dbs*)
      tbl))

  (let _sref sref
    (def sref (com val ind)
      (do1 (_sref com val ind)
        (awhen (and (isa com 'table) (alref dbs* com)) (it))))
  )