We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c6ab449 commit 943852aCopy full SHA for 943852a
lib/internal/util.js
@@ -694,7 +694,26 @@ function isArrayBufferDetached(value) {
694
return false;
695
}
696
697
+/**
698
+ * Helper function to lazy-load an initialize-once value.
699
+ * @template T Return value of initializer
700
+ * @param {()=>T} initializer Initializer of the lazily loaded value.
701
+ * @returns {()=>T}
702
+ */
703
+function getLazy(initializer) {
704
+ let value;
705
+ let initialized = false;
706
+ return function() {
707
+ if (initialized === false) {
708
+ value = initializer();
709
+ initialized = true;
710
+ }
711
+ return value;
712
+ };
713
+}
714
+
715
module.exports = {
716
+ getLazy,
717
assertCrypto,
718
cachedResult,
719
convertToValidSignal,
0 commit comments