-
-
Save MasterDuke17/c2769796f3a693ee5d836c5a5f73788e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/experimental.rakumod b/lib/experimental.rakumod | |
index 4f6694e5b..c441ad4ec 100644 | |
--- a/lib/experimental.rakumod | |
+++ b/lib/experimental.rakumod | |
@@ -3,11 +3,16 @@ | |
package EXPORT::cached { | |
multi sub trait_mod:<is>(Routine $r, :$cached!) { | |
my %cache; | |
+ my $lock = Lock.new; | |
$r.wrap(-> |c { | |
my $key := c.gist; | |
- %cache.EXISTS-KEY($key) | |
- ?? %cache{$key} | |
- !! (%cache{$key} := callsame); | |
+ if %cache.EXISTS-KEY($key) { | |
+ %cache{$key} | |
+ } | |
+ else { | |
+ my &target = nextcallee; | |
+ $lock.protect: { %cache{$key} := target(|c) } | |
+ } | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment