.. role:: ts-api-decorator

#############
UnsafePromise
#############

.. js:module:: Util
   :noindex:

.. container:: ts-api-section

   .. js:class:: UnsafePromise

      This represents a ``Promise`` that has its promised return value immediately available.
      The immediate value is unsafe to use (safety depends on specific use cases) until
      this ``UnsafePromise`` becomes marked as ready.

      The primary use case of this would be to synchronously return a reference to an object
      that needs to wait for an ``init(): Promise<void>`` function to complete.



.. container:: api-index-section

   .. rubric:: Properties

   .. rst-class:: api-index-list-item api-kind-property api-parent-kind-interface

   * :js:attr:`~Util.UnsafePromise.[toStringTag]`
   * :js:attr:`~Util.UnsafePromise.isReady`
   * :js:attr:`~Util.UnsafePromise.readyPromise`
   * :js:attr:`~Util.UnsafePromise.unsafeValue`



.. container:: api-index-section

   .. rubric:: Methods

   .. rst-class:: api-index-list-item api-kind-method api-parent-kind-interface

   * :js:meth:`~Util.UnsafePromise.catch`
   * :js:meth:`~Util.UnsafePromise.finally`
   * :js:meth:`~Util.UnsafePromise.then`





------------

Properties
==========

.. container:: ts-api-section

   .. js:attribute:: UnsafePromise.[toStringTag]

      :type: string





.. container:: ts-api-section

   .. js:attribute:: UnsafePromise.isReady

      :type: boolean

      This value becomes ``true`` once ``this.readyPromise`` resolves. If ``this.readyPromise`` rejects, this
      value never becomes ``true``.



.. container:: ts-api-section

   .. js:attribute:: UnsafePromise.readyPromise

      :type: Promise <void>

      This promise resolves once ``this.unsafeValue`` is safe to access.



.. container:: ts-api-section

   .. js:attribute:: UnsafePromise.unsafeValue

      :type: T

      An unsafe synchronous reference to the value returned through this promise's ``then()`` callback.



Methods
=======

.. rst-class:: ts-api-section

catch
-----

.. js:method:: UnsafePromise.catch([ onrejected])

   :param onrejected: :ts-api-decorator:`optional` The callback to execute when the Promise is rejected.
   :type onrejected: null | function


   Attaches a callback for only the rejection of the Promise.

   :returns: A Promise for the completion of the callback.


   :rtype: Promise <T | TResult>




   .. js:function:: onrejected( reason)
      :noindex:

      :param reason: None
      :type reason: any


      :rtype: TResult | PromiseLike <TResult>



.. rst-class:: ts-api-section

finally
-------

.. js:method:: UnsafePromise.finally([ onfinally])

   :param onfinally: :ts-api-decorator:`optional` The callback to execute when the Promise is settled (fulfilled or rejected).
   :type onfinally: null | function


   Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
   resolved value cannot be modified from the callback.

   :returns: A Promise for the completion of the callback.


   :rtype: Promise <T>




   .. js:function:: onfinally()
      :noindex:



      :rtype: void



.. rst-class:: ts-api-section

then
----

.. js:method:: UnsafePromise.then([ onfulfilled[, onrejected]])

   :param onfulfilled: :ts-api-decorator:`optional` The callback to execute when the Promise is resolved.
   :type onfulfilled: null | function
   :param onrejected: :ts-api-decorator:`optional` The callback to execute when the Promise is rejected.
   :type onrejected: null | function


   Attaches callbacks for the resolution and/or rejection of the Promise.

   :returns: A Promise for the completion of which ever callback is executed.


   :rtype: Promise <TResult1 | TResult2>




   .. js:function:: onfulfilled( value)
      :noindex:

      :param value: None
      :type value: T


      :rtype: TResult1 | PromiseLike <TResult1>

   .. js:function:: onrejected( reason)
      :noindex:

      :param reason: None
      :type reason: any


      :rtype: TResult2 | PromiseLike <TResult2>



