Files
cloudron-box/src/once.js

20 lines
469 B
JavaScript
Raw Normal View History

2022-04-15 19:01:35 -05:00
'use strict';
exports = module.exports = once;
2022-11-05 15:36:07 +01:00
const debug = require('debug')('box:once');
2022-04-15 19:01:35 -05:00
// https://github.com/isaacs/once/blob/main/LICENSE (ISC)
function once (fn) {
const f = function () {
2022-11-05 15:36:07 +01:00
if (f.called) {
debug(`${f.name} was already called, returning previous return value`);
return f.value;
}
2022-04-15 19:01:35 -05:00
f.called = true;
return f.value = fn.apply(this, arguments);
};
f.called = false;
return f;
}