| 1 |
(* result.sml |
| 2 |
* 2004 Matthew Fluet ([email protected]) |
| 3 |
* Ported to MLton threads. |
| 4 |
*) |
| 5 |
|
| 6 |
(* result.sml |
| 7 |
* |
| 8 |
* COPYRIGHT (c) 1996 AT&T Research. |
| 9 |
* |
| 10 |
*) |
| 11 |
|
| 12 |
structure Result :> RESULT = |
| 13 |
struct |
| 14 |
|
| 15 |
structure SV = SyncVar |
| 16 |
|
| 17 |
datatype 'a result_val = EXN of exn | RES of 'a |
| 18 |
|
| 19 |
type 'a result = 'a result_val SV.ivar |
| 20 |
|
| 21 |
fun result () = SV.iVar() |
| 22 |
fun put (iv, v) = SV.iPut(iv, RES v) |
| 23 |
fun putExn (iv, ex) = SV.iPut(iv, EXN ex) |
| 24 |
fun wrap (RES v) = v |
| 25 |
| wrap (EXN ex) = raise ex |
| 26 |
fun get iv = wrap(SV.iGet iv) |
| 27 |
fun getEvt iv = CML.wrap(SV.iGetEvt iv, wrap) |
| 28 |
end |