Add fetch* utils
This commit is contained in:
@ -1,7 +1,20 @@
|
||||
function createMutex(doWork) {
|
||||
const invariant = require("invariant");
|
||||
|
||||
function defaultCreateKey(payload) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
function createMutex(doWork, createKey = defaultCreateKey) {
|
||||
const mutex = Object.create(null);
|
||||
|
||||
return (key, payload, callback) => {
|
||||
return (payload, callback) => {
|
||||
const key = createKey(payload);
|
||||
|
||||
invariant(
|
||||
typeof key === "string",
|
||||
"Mutex needs a string key; please provide a createKey function that returns a string"
|
||||
);
|
||||
|
||||
if (mutex[key]) {
|
||||
mutex[key].push(callback);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user