From: Tim Vaughan Date: Thu, 15 Apr 2021 14:27:27 +0000 (+0200) Subject: Can save/restore actor table to/from disk. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=actors.git Can save/restore actor table to/from disk. --- diff --git a/actors.scm b/actors.scm index fc266a3..1c19346 100644 --- a/actors.scm +++ b/actors.scm @@ -6,12 +6,17 @@ send-and-run restart enable-trace - disable-trace) + disable-trace + save-actors + save-actors-to + load-actors + load-actors-from) (import scheme (chicken base) srfi-69 - matchable) + matchable + s11n) (define trace-enabled #f) ;used for debugging @@ -151,4 +156,23 @@ (define (restart) (set! message-queue (make-fifo)) - (set! actor-table (make-hash-table)))) + (set! actor-table (make-hash-table))) + +;;; +;;; Serialization +;;; + + (define (save-actors-to filename) + (with-output-to-file filename + (lambda () + (serialize (hash-table->alist actor-table))))) + + (define (save-actors) + (save-actors-to "image")) + + (define (load-actors-from filename) + (set! actor-table + (alist->hash-table (with-input-from-file filename deserialize)))) + + (define (load-actors) + load-actors-from "image")) diff --git a/testing_factorial1.scm b/testing_factorial1.scm index aa3d1f0..0041f33 100644 --- a/testing_factorial1.scm +++ b/testing_factorial1.scm @@ -1,4 +1,5 @@ -(import actors) +(import actors + matchable) (enable-trace)