Created
September 26, 2016 17:38
-
-
Save jmakeig/b84020b313af4ae0f871d3a9ee2ab58c to your computer and use it in GitHub Desktop.
Synchronous pseudo-promises in MarkLogic
This file contains hidden or 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
| fetch('http://www.marklogic.com') | |
| .then(console.log); | |
This file contains hidden or 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
| 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/'))); | |
| }); | |
| } |
This file contains hidden or 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
| '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