]> gitweb.factorcode.org Git - factor.git/commitdiff
retries: Swap the order of args to retries combinator
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 1 Apr 2021 04:00:41 +0000 (23:00 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 1 Apr 2021 04:00:41 +0000 (23:00 -0500)
[ "/bin" XATTR_NOFOLLOW swapd list-xattrs-impl ]
<immediate> { 2 4 100000 } retries .

    [ 2 = [ "not 2!" throw ] unless ]
    10 20 <random-wait> 3 retries

looks better than

    [ 2 = [ "not 2!" throw ] unless ]
    3 10 20 <random-wait> retries ! old

basis/retries/retries-tests.factor
basis/retries/retries.factor
basis/unix/xattrs/macos/macos.factor

index 87092766d89d456009d1283651c05e6da6ec0e7d..1c80a9c664bbe63473ab224b9b28794920752465 100644 (file)
@@ -6,66 +6,66 @@ IN: retries.tests
 ! try every value in a sequence with no sleeps
 [
     [ dup 2 = [ "not 2!" throw ] unless ]
-    { 1 } <immediate> retries
+    <immediate> { 1 } retries
 ] [ retries-failed? ] must-fail-with
 
 { 2 } [
     [ dup 2 = [ "not 2!" throw ] unless ]
-    { 1 2 } <immediate> retries
+    <immediate> { 1 2 } retries
 ] unit-test
 
 ! try every value in a sequence with a random sleep
 [
     [ dup 2 = [ "not 2!" throw ] unless ]
-    { 1 } 10 20 <random-wait> retries
+    10 20 <random-wait> { 1 } retries
 ] [ retries-failed? ] must-fail-with
 
 { 2 } [
     [ dup 2 = [ "not 2!" throw ] unless ]
-    { 1 2 } 10 20 <random-wait> retries
+    10 20 <random-wait> { 1 2 } retries
 ] unit-test
 
 ! try every value in a sequence with an exponentially increasing sleep
 [
     [ dup 2 = [ "not 2!" throw ] unless ]
-    { 1 } 1.1 100 <exponential-wait> retries
+    1.1 100 <exponential-wait> { 1 } retries
 ] [ retries-failed? ] must-fail-with
 
 { 2 } [
     [ dup 2 = [ "not 2!" throw ] unless ]
-    { 1 2 } 1.1 100 <exponential-wait> retries
+    1.1 100 <exponential-wait> { 1 2 } retries
 ] unit-test
 
 
 ! try n times with no sleeps
 [
     [ 2 = [ "not 2!" throw ] unless ]
-    2 <immediate> retries
+    <immediate> 2 retries
 ] [ retries-failed? ] must-fail-with
 
 { } [
     [ 2 = [ "not 2!" throw ] unless ]
-    3 <immediate> retries
+    <immediate> 3 retries
 ] unit-test
 
 ! try n times with a random sleep
 [
     [ 2 = [ "not 2!" throw ] unless ]
-    2 10 20 <random-wait> retries
+    10 20 <random-wait> 2 retries
 ] [ retries-failed? ] must-fail-with
 
 { } [
     [ 2 = [ "not 2!" throw ] unless ]
-    3 10 20 <random-wait> retries
+    10 20 <random-wait> 3 retries
 ] unit-test
 
 ! try n times with an exponentially increasing sleep
 [
     [ 2 = [ "not 2!" throw ] unless ]
-    2 1.1 100 <exponential-wait> retries
+    1.1 100 <exponential-wait> 2 retries
 ] [ retries-failed? ] must-fail-with
 
 { } [
     [ 2 = [ "not 2!" throw ] unless ]
-    3 1.1 100 <exponential-wait> retries
+     1.1 100 <exponential-wait> 3 retries
 ] unit-test
\ No newline at end of file
index c16ac878b78f736622ab5d872064f2fe7695924f..22fff548a5588b9294c317d7afa373ecd61033c5 100644 (file)
@@ -6,23 +6,24 @@ namespaces prettyprint random sequences system threads ;
 IN: retries
 
 TUPLE: retries count time-strategy errors ;
-: new-retries ( time-strategy class -- obj )
+: new-retries ( class -- obj )
     new
-        swap >>time-strategy
         0 >>count
         V{ } clone >>errors ; inline
 
 TUPLE: counted-retries < retries max-retries ;
-: <counted-retries> ( max time-strategy -- retries )
+: <counted-retries> ( time-strategy max-retries -- retries )
     counted-retries new-retries
-        swap >>max-retries ;
+        swap >>max-retries
+        swap >>time-strategy ; inline
 
 TUPLE: sequence-retries < retries seq ;
-: <sequence-retries> ( seq time-strategy -- retries )
+: <sequence-retries> ( time-strategy seq -- retries )
     sequence-retries new-retries
-        swap >>seq ;
+        swap >>seq
+        swap >>time-strategy ; inline
 
-GENERIC#: retries* 1 ( seq/n time-strategy -- obj )
+GENERIC: retries* ( time-strategy seq/n -- obj )
 M: integer retries* <counted-retries> ;
 M: sequence retries* <sequence-retries> ;
 
@@ -72,5 +73,5 @@ ERROR: retries-failed retries quot ;
         ] loop1
     ] with-variable ; inline
 
-: retries ( quot time-strategy -- result )
+: retries ( quot time-strategy n/seq -- result )
     retries* swap with-retries ; inline
index cf5f8dcb7d8dac48f3a57a7030f299f460408a92..d325fe5edd4d80f7a016c0110ac4b4ed643d7e0b 100644 (file)
@@ -10,4 +10,4 @@ IN: unix.xattrs.macos
 
 : list-xattrs ( path flags -- out )
     '[ _ _ swapd list-xattrs-impl ]
-    ${ 512 16384 XATTR_MAXSIZE } <immediate> retries ;
+    <immediate> ${ 512 16384 XATTR_MAXSIZE } retries ;