From f7c322f83aaef1ea7d46c4cd620f0f13aedf47dc Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 15 Sep 2008 10:30:06 -0500 Subject: [PATCH] make a couple words private, use ERROR: instead of throwing strings --- basis/concurrency/combinators/combinators.factor | 4 ++++ basis/concurrency/count-downs/count-downs.factor | 8 ++++++-- basis/concurrency/messaging/messaging.factor | 9 +++++++-- basis/concurrency/promises/promises.factor | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/basis/concurrency/combinators/combinators.factor b/basis/concurrency/combinators/combinators.factor index eab0ed4cb4..ab3ca7ed4a 100755 --- a/basis/concurrency/combinators/combinators.factor +++ b/basis/concurrency/combinators/combinators.factor @@ -4,8 +4,10 @@ USING: concurrency.futures concurrency.count-downs sequences kernel ; IN: concurrency.combinators +r r> keep await ; inline +PRIVATE> : parallel-each ( seq quot -- ) over length [ @@ -20,7 +22,9 @@ IN: concurrency.combinators : parallel-filter ( seq quot -- newseq ) over >r pusher >r each r> r> like ; inline + : parallel-map ( seq quot -- newseq ) [ curry future ] curry map future-values ; diff --git a/basis/concurrency/count-downs/count-downs.factor b/basis/concurrency/count-downs/count-downs.factor index 93cef250a1..c4bc92c688 100755 --- a/basis/concurrency/count-downs/count-downs.factor +++ b/basis/concurrency/count-downs/count-downs.factor @@ -11,14 +11,18 @@ TUPLE: count-down n promise ; : count-down-check ( count-down -- ) dup n>> zero? [ t swap promise>> fulfill ] [ drop ] if ; +ERROR: invalid-count-down-count count ; + : ( n -- count-down ) - dup 0 < [ "Invalid count for count down" throw ] when + dup 0 < [ invalid-count-down-count ] when \ count-down boa dup count-down-check ; +ERROR: count-down-already-done ; + : count-down ( count-down -- ) dup n>> dup zero? - [ "Count down already done" throw ] + [ count-down-already-done ] [ 1- >>n count-down-check ] if ; : await-timeout ( count-down timeout -- ) diff --git a/basis/concurrency/messaging/messaging.factor b/basis/concurrency/messaging/messaging.factor index 12b5d270d4..03d1304527 100755 --- a/basis/concurrency/messaging/messaging.factor +++ b/basis/concurrency/messaging/messaging.factor @@ -4,7 +4,7 @@ ! Concurrency library for Factor, based on Erlang/Termite style ! concurrency. USING: kernel threads concurrency.mailboxes continuations -namespaces assocs random accessors ; +namespaces assocs random accessors summary ; IN: concurrency.messaging GENERIC: send ( message thread -- ) @@ -52,9 +52,14 @@ TUPLE: reply data tag ; [ >r tag>> r> tag>> = ] [ 2drop f ] if ; +ERROR: cannot-send-synchronous-to-self message thread ; + +M: cannot-send-synchronous-to-self summary + drop "Cannot synchronous send to myself" ; + : send-synchronous ( message thread -- reply ) dup self eq? [ - "Cannot synchronous send to myself" throw + cannot-send-synchronous-to-self ] [ >r dup r> send [ synchronous-reply? ] curry receive-if diff --git a/basis/concurrency/promises/promises.factor b/basis/concurrency/promises/promises.factor index 511decdf35..382697e04f 100755 --- a/basis/concurrency/promises/promises.factor +++ b/basis/concurrency/promises/promises.factor @@ -11,9 +11,10 @@ TUPLE: promise mailbox ; : promise-fulfilled? ( promise -- ? ) mailbox>> mailbox-empty? not ; +ERROR: promise-already-fulfilled promise ; : fulfill ( value promise -- ) dup promise-fulfilled? [ - "Promise already fulfilled" throw + promise-already-fulfilled ] [ mailbox>> mailbox-put ] if ;