Skip to content

Instantly share code, notes, and snippets.

@jmakeig
Created September 26, 2016 17:38
Show Gist options
  • Select an option

  • Save jmakeig/b84020b313af4ae0f871d3a9ee2ab58c to your computer and use it in GitHub Desktop.

Select an option

Save jmakeig/b84020b313af4ae0f871d3a9ee2ab58c to your computer and use it in GitHub Desktop.
Synchronous pseudo-promises in MarkLogic
fetch('http://www.marklogic.com')
.then(console.log);
function Request(url, options) {
this.url = url;
options = options || {};
this.method = options.method;
this.headers = options.headers;
this.body = options.body;
}
Object.assign(Request.prototype, {});
/**
*
* @param {string|Request} request
* @return Promise
*/
function fetch(request) {
return new SynchPromise(function(resolve, reject) {
resolve(fn.head(xdmp.httpGet('http://www.marklogic.com/')));
});
}
'use strict'
/**
* @param {function(resolve, reject)} executor
*/
function SynchPromise(executor) {
this.executor = executor;
}
Object.assign(SynchPromise.prototype,
{
then(onFulfilled, onRejected) {
this.executor(onFulfilled, onRejected);
},
catch(callback) { return false; },
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment