Created
March 1, 2018 15:10
-
-
Save maman/014533696b52ca78e81025d89fc03521 to your computer and use it in GitHub Desktop.
Trying react new simpleCacheProvider module
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
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