-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Milestone
Description
It would be neat to support Promises for the fetcher. This would expand the audience of crisp-cache.
In chatting with @eschwartz he had some ideas:
function callbackify(promiseFn) {
return function() {
const args = [].slice.call(arguments, 0);
const promiseFnArgs = args.slice(0, arguments.length - 1);
const cb = args[args.length - 1];
promiseFn.apply(null, promiseFnArgs)
.then(res => cb(null, res), err => cb(err));
}
}const thunk = callbackify(() => Promise.resolve('foo'));
thunk((err, res) => assert(res === 'foo'))