No Description

resolve.js 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {
  2. noop,
  3. resolve as _resolve
  4. } from '../-internal';
  5. /**
  6. `Promise.resolve` returns a promise that will become resolved with the
  7. passed `value`. It is shorthand for the following:
  8. ```javascript
  9. var promise = new Promise(function(resolve, reject){
  10. resolve(1);
  11. });
  12. promise.then(function(value){
  13. // value === 1
  14. });
  15. ```
  16. Instead of writing the above, your code now simply becomes the following:
  17. ```javascript
  18. var promise = Promise.resolve(1);
  19. promise.then(function(value){
  20. // value === 1
  21. });
  22. ```
  23. @method resolve
  24. @static
  25. @param {Any} value value that the returned promise will be resolved with
  26. Useful for tooling.
  27. @return {Promise} a promise that will become fulfilled with the given
  28. `value`
  29. */
  30. export default function resolve(object) {
  31. /*jshint validthis:true */
  32. var Constructor = this;
  33. if (object && typeof object === 'object' && object.constructor === Constructor) {
  34. return object;
  35. }
  36. var promise = new Constructor(noop);
  37. _resolve(promise, object);
  38. return promise;
  39. }