Skip to content

Commit

Permalink
Update to use better promising and no fetchCache
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 26, 2018
1 parent ccf6c91 commit ad60593
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/JBrowse/Model/XHRBlob.js
@@ -1,6 +1,5 @@
cjsRequire('whatwg-fetch')
const tenaciousFetch = cjsRequire('tenacious-fetch').default
const LRU = cjsRequire('quick-lru')


const { HttpRangeFetcher } = cjsRequire('http-range-fetcher')
Expand All @@ -12,8 +11,6 @@ define( [ 'dojo/_base/declare',
],
function( declare, Util, FileBlob ) {

const fetchCache = new LRU({ maxSize: 20 })

function getfetch(url, opts = {}) {
let mfetch
if(Util.isElectron()) {
Expand All @@ -26,11 +23,7 @@ function getfetch(url, opts = {}) {
} else {
mfetch = tenaciousFetch
}
var r = fetchCache.get(url)
if(r) {
return r
}
var p = mfetch(url, Object.assign({
return mfetch(url, Object.assign({
method: 'GET',
credentials: 'same-origin',
retries: 5,
Expand All @@ -40,8 +33,6 @@ function getfetch(url, opts = {}) {
console.warn(`${url} request failed, retrying (${retriesLeft} retries left)`)
}
}, opts))
fetchCache.set(p)
return p
}

function fetchBinaryRange(url, start, end) {
Expand Down Expand Up @@ -156,11 +147,10 @@ var XHRBlob = declare( FileBlob,
if (length < 0) {
throw new Error('Length less than 0 received')
} else if(length == undefined && this.start == 0) {
getfetch(this.url).then(response => {
response.arrayBuffer().then(res => {
callback(res)
}, failCallback)
}, failCallback)
getfetch(this.url)
.then(res => res.arrayBuffer())
.then(callback)
.catch(failCallback)
} else {
globalCache.getRange(this.url, this.start, length)
.then(
Expand Down

0 comments on commit ad60593

Please sign in to comment.