Changeset 35443 in project


Ignore:
Timestamp:
04/26/18 03:13:17 (5 weeks ago)
Author:
kon
Message:

rel 1.1.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/timed-resource

    r26886 r35443  
    1414=== make-timed-resource
    1515
    16 <procedure>(make-timed-resource OPENER CLOSER TIMEOUT [NAME]) => timed-resource</procedure>
     16<procedure>(make-timed-resource OPENER CLOSER TIMEOUT [NAME]) -> timed-resource</procedure>
    1717
    1818Returns a new {{timed-resource}} object that covers a resource with a lifetime
     
    2121end of its' life.
    2222
    23 The {{OPENER}} is a {{(procedure () *)}} returning the resource object.
    24 
    25 The {{CLOSER}} is a {{(procedure (*))}} taking a resource object returned by
    26 the {{OPENER}}.
    27 
    28 The {{NAME}} is used as a prefix for the generated unique identifier of the
    29 created {{timed-resource}} and is usually a {{string}} or {{symbol}}. There is
    30 no semantic content.
     23; {{OPENER}} : {{(procedure () *)}} ; returns the {{resource-object}}
     24; {{CLOSER}} : {{(procedure (*))}} ; takes the {{resource-object}} (returned by {{OPENER}})
     25; {{TIMEOUT}} : {{number}} ; seconds
     26; {{NAME}} : {{*}} ; prefix for the {{gensym}} of the created {{timed-resource}}
    3127
    3228No attempt is made to serialize access to a resource, this is up to the caller;
     
    3935=== with-timed-resource
    4036
    41 <procedure>(with-timed-resource TIMED-RESOURCE ACTION) => *</procedure>
     37<procedure>(with-timed-resource TIMED-RESOURCE ACTION) -> *</procedure>
    4238
    4339Returns the result of invoking {{ACTION}} with the resource covered by the
     
    4844
    4945=== timed-resource?
     46=== check-timed-resource
     47=== error-timed-resource
    5048
    51 <procedure>(timed-resource? OBJECT) => boolean</procedure>
     49<procedure>(timed-resource? OBJECT) -> boolean</procedure>
    5250
    5351Is the {{OBJECT}} a {{timed-resource}}?
     
    5553=== timed-resource-name
    5654
    57 <procedure>(timed-resource-name TIMED-RESOURCE) => *</procedure>
     55<procedure>(timed-resource-name TIMED-RESOURCE) -> *</procedure>
    5856
    5957Returns unique id for {{TIMED-RESOURCE}}.
    6058
    61 === timed-resource-timeout
     59=== default-timed-resource-timeout
    6260
    63 <procedure>(timed-resource-timeout) => (or #f number)</procedure>
    64 <procedure>(timed-resource-timeout SECONDS) => </procedure>
     61<procedure>(default-timed-resource-timeout) -> (or #f number)</procedure>
     62<procedure>(default-timed-resource-timeout SECONDS) -> </procedure>
    6563
    6664Gets & sets the number of seconds to wait for a thread to quit.
     
    8280
    8381(define random-blob
    84   (let ((tr-random-dev
    85           (make-timed-resource
    86             ;Use the random device (*nix only)
    87             (lambda () (open-input-file "/dev/random" #:binary))
    88             (lambda (port) (close-output-port port))
    89             ;Only keep open for 10 seconds
    90             10.0)))
     82  (let (
     83    (*tr-random-dev*
     84      (make-timed-resource
     85        ;random device (*nix only)
     86        (lambda () (open-input-file "/dev/random" #:binary))
     87        (lambda (port) (close-output-port port))
     88        ;open for 10 seconds
     89        10.0))
     90    (round-bytes
     91      (lambda (x) (fx/ (fx+ x 7) 8))) )
    9192    (lambda (#!optional (bits 128))
    92       (let ((bytes (inexact->exact (floor (/ (+ bits 7) 8)))))
    93         (with-timed-resource tr-random-dev
    94           (lambda (port)
    95             (u8vector->blob (read-u8vector bytes))))) ) ) )
     93      (with-timed-resource *tr-random-dev*
     94        (lambda (port)
     95          (u8vector->blob (read-u8vector (round-bytes bits))))) ) ) )
    9696</enscript>
    9797
     
    111111[[check-errors]]
    112112
     113[[setup-helper]]
     114
    113115
    114116== Author
     
    119121== Version history
    120122
     123; 1.1.0 : Add types.
    121124; 1.0.2 : Use compiled setup-helper (& un-hide).
    122125; 1.0.1 : Fix for reporting an expected condition, ''timed-resource-closed'', during shutdown.
     
    126129== License
    127130
    128 Copyright (C) 2010 Kon Lovett.  All rights reserved.
     131Copyright (C) 2010-2017 Kon Lovett.  All rights reserved.
    129132
    130133Permission is hereby granted, free of charge, to any person obtaining a
Note: See TracChangeset for help on using the changeset viewer.