Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Add timeout for fetch requests for #8
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Jan 24, 2014
1 parent 711c4e3 commit 5496a37
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
14 changes: 11 additions & 3 deletions lib/fetcherWithPromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ $rdf.Fetcher.prototype.proxiedURL = function(uri) {
}


var hardcodedFetcherTimeout = 5000; // in millies, temporary hardcoded

/**
* return the Promise of a graph fro a given url
* @param {String} uri to fetch as string (!) (Not a $rdf.sym())
Expand All @@ -35,6 +37,7 @@ $rdf.Fetcher.prototype.fetch = function(uri, referringTerm, force) {

//console.log("============> fetch with promise! <"+uri+">");

// TODO Henry document this please
var requestedUriOrProxy = function(uri2){
return (self.requiresProxy(uri))?
(uri2 == uri || ( $rdf.Fetcher.crossSiteProxy(uri) == uri2 )) :
Expand All @@ -60,20 +63,25 @@ $rdf.Fetcher.prototype.fetch = function(uri, referringTerm, force) {
return !requestedUriOrProxy(uri2) ; // Call me again?
});
self.addCallback('fail', function(uri2, status) {
if (requestedUriOrProxy(uri2)) deferred.reject("Asynch fetch fail: " + status + " for " + uri );
if (requestedUriOrProxy(uri2)) {
deferred.reject("Asynch fetch fail: " + status + " for " + uri );
}
return (!requestedUriOrProxy(uri2)); // Call me again?
});

if (sta == 'unrequested') {
var proxyURI = (self.requiresProxy(uri))?$rdf.Fetcher.crossSiteProxy(uri):docUri
// console.log("proxyURI=",proxyURI)
var result = self.requestURI(proxyURI, referringTerm, force);
var result = self.requestURI(proxyURI, referringTerm, force);
if (result == null) {
//console.log("graph("+uriSym+") was already in store ( or ... check!)");
deferred.resolve($rdf.pointedGraph(self.store, uriSym, uriSym, uriSym));
}
}
return deferred.promise;

// See https://github.com/stample/react-foaf/issues/8 -> RDFLib doesn't always fire the "fail" callback :(
return Q.timeout(deferred.promise, hardcodedFetcherTimeout, "Timeout fired after "+hardcodedFetcherTimeout+" because no response from RDFLib :( (rdflib bug)");
}

}

19 changes: 12 additions & 7 deletions scripts/contacts/PersonContactOnProfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx React.DOM */

var PersonContactOnProfile = React.createClass({
mixins: [WithLogger,WithLifecycleLoggingLite],
mixins: [WithLogger,WithLifecycleLogging],
componentName: "PersonContactOnProfile",

propTypes: {
Expand All @@ -10,27 +10,31 @@ var PersonContactOnProfile = React.createClass({
filterText: React.PropTypes.string.isRequired,
// Optional:
jumpedPersonPG: React.PropTypes.instanceOf($rdf.PointedGraph),
jumpFailure: React.PropTypes.bool
jumpError: React.PropTypes.object
},


handleClick: function(e) {
// TODO maybe not appropriate? we may be able to click on a namednode before it has been jumped?
if ( this.props.jumpedPersonPG ) {
this.props.onPersonContactClick();
}
else if ( this.props.jumpError ) {
alert("Error during jump, can't click on this graph:\n"+JSON.stringify(this.props.jumpError));
}
else {
alert("graph not jumped: can't click on it");
alert("Graph not jumped");
}
return true;
},


isJumpFailure: function() {
return this.props.jumpFailure;
isJumpError: function() {
return !!this.props.jumpError;
},

isNotJumpedYet: function() {
return !this.props.jumpedPersonPG && !this.isJumpFailure();
return !this.props.jumpedPersonPG && !this.isJumpError();
},

getGraphList: function() {
Expand All @@ -51,9 +55,10 @@ var PersonContactOnProfile = React.createClass({
'clearfix': true,
'float-left': true,
'loading': this.isNotJumpedYet(),
'error': this.isJumpFailure(),
'error': this.isJumpError(),
'filtered-user' : !this.displayUser(graphList)
});
this.debug("Classes Render person2. Jump error? ",this.props.jumpError);

// Return.
return (
Expand Down
4 changes: 2 additions & 2 deletions scripts/contacts/PersonContactOnProfileJumpWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var PersonContactOnProfileJumpWrapper = React.createClass({
function(err) {
self.error("Can't jump pg:",err);
self.replaceState({
jumpFailure: true
jumpError: err
});
}
)
Expand All @@ -45,7 +45,7 @@ var PersonContactOnProfileJumpWrapper = React.createClass({
onPersonContactClick={this.props.onPersonContactClick}
personPG={this.props.personPG}
jumpedPersonPG={this.state.jumpedPersonPG}
jumpFailure={this.state.jumpFailure}
jumpError={this.state.jumpError}
filterText={this.props.filterText}/>
)
}
Expand Down

0 comments on commit 5496a37

Please sign in to comment.