Skip to content

Instantly share code, notes, and snippets.

@maman
Created March 1, 2018 15:10
Show Gist options
  • Save maman/014533696b52ca78e81025d89fc03521 to your computer and use it in GitHub Desktop.
Save maman/014533696b52ca78e81025d89fc03521 to your computer and use it in GitHub Desktop.
Trying react new simpleCacheProvider module
const test = async () => {
const { createCache, createResource } = require('./cacheProvider');
function loadUpperCase(text) {
console.log('CALLED!');
return Promise.resolve(text.toUpperCase());
}
function loadUpperCase2(text) {
console.log('CALLED 2!');
return Promise.resolve(text.toLowerCase());
}
const UpperCase = createResource(loadUpperCase);
const UpperCase2 = createResource(loadUpperCase2)
const cache = createCache();
let suspender;
try {
UpperCase.read(cache, 'cok');
} catch (v) {
suspender = v;
}
await suspender;
let suspender2;
try {
UpperCase2.read(cache, 'COK');
} catch (v) {
suspender2 = v;
}
await suspender2;
const result = UpperCase2.read(cache, 'COK');
const result2 = UpperCase.read(cache, 'cok');
const result3 = UpperCase.read(cache, 'cok');
const result4 = UpperCase2.read(cache, 'COK');
console.log('RESULT:1', result);
console.log('RESULT:2', result2);
console.log('RESULT:3', result3);
console.log('RESULT:4', result4);
};
test();
/**
======
result
======
$ node index2.js
CALLED!
CALLED 2!
RESULT:1 cok
RESULT:2 COK
RESULT:3 COK
RESULT:4 cok
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment