Skip to content

Support fetcher returning Promise #27

@four43

Description

@four43

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'))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions