Shaka Player Embedded
Public Member Functions | Static Public Member Functions | List of all members
shaka::Promise Class Reference

#include <promise.h>

Inheritance diagram for shaka::Promise:
shaka::GenericConverter shaka::memory::Traceable

Public Member Functions

 Promise ()
 
 ~Promise () override
 
 Promise (const Promise &)
 
 Promise (Promise &&)
 
Promiseoperator= (const Promise &)
 
Promiseoperator= (Promise &&)
 
bool TryConvert (Handle< JsValue > value) override
 
ReturnVal< JsValue > ToJsValue () const override
 
void Trace (memory::HeapTracer *tracer) const override
 
bool CanResolve () const
 
void ResolveWith (Handle< JsValue > value, bool run_events=true)
 
void RejectWith (const js::JsError &error, bool run_events=true)
 
void Then (std::function< void(Any)> on_resolve, std::function< void(Any)> on_reject)
 
- Public Member Functions inherited from shaka::GenericConverter
virtual ~GenericConverter ()
 
- Public Member Functions inherited from shaka::memory::Traceable
virtual ~Traceable ()
 
virtual bool IsRootedAlive () const
 
virtual bool IsShortLived () const
 

Static Public Member Functions

static std::string name ()
 
static Promise PendingPromise ()
 
static Promise Resolved ()
 
static Promise Resolved (Handle< JsValue > value)
 
static Promise Rejected (const js::JsError &error)
 

Additional Inherited Members

- Static Public Attributes inherited from shaka::memory::Traceable
static constexpr const uint64_t kShortLiveDurationMs = 5000
 

Detailed Description

Defines a wrapper around a JavaScript Promise. This manages two kinds of Promises: (1) those created by us and (2) those created in JavaScript.

Definition at line 37 of file promise.h.

Constructor & Destructor Documentation

§ Promise() [1/3]

shaka::Promise::Promise ( )

An invalid Promise; you must use TryConvert or the assignment operator to get a valid Promise.

Definition at line 65 of file promise.cc.

§ ~Promise()

shaka::Promise::~Promise ( )
override

Definition at line 66 of file promise.cc.

§ Promise() [2/3]

shaka::Promise::Promise ( const Promise )
default

§ Promise() [3/3]

shaka::Promise::Promise ( Promise &&  )
default

Member Function Documentation

§ CanResolve()

bool shaka::Promise::CanResolve ( ) const
inline

Whether the Promise can be resolved/rejected.

Definition at line 88 of file promise.h.

§ name()

static std::string shaka::Promise::name ( )
inlinestatic

Definition at line 39 of file promise.h.

§ operator=() [1/2]

Promise & shaka::Promise::operator= ( const Promise )
default

§ operator=() [2/2]

Promise & shaka::Promise::operator= ( Promise &&  )
default

§ PendingPromise()

static Promise shaka::Promise::PendingPromise ( )
inlinestatic

Creates a Promise that represents a pending Promise. The ResolveWith/RejectWith methods can be use to complete it.

Definition at line 54 of file promise.h.

§ Rejected()

static Promise shaka::Promise::Rejected ( const js::JsError error)
inlinestatic

Definition at line 77 of file promise.h.

§ RejectWith()

void shaka::Promise::RejectWith ( const js::JsError error,
bool  run_events = true 
)

Definition at line 121 of file promise.cc.

§ Resolved() [1/2]

static Promise shaka::Promise::Resolved ( )
inlinestatic

Definition at line 64 of file promise.h.

§ Resolved() [2/2]

static Promise shaka::Promise::Resolved ( Handle< JsValue >  value)
inlinestatic

Definition at line 71 of file promise.h.

§ ResolveWith()

void shaka::Promise::ResolveWith ( Handle< JsValue >  value,
bool  run_events = true 
)

Resolves the Promise with the given value. This can only be called if the contained Promise was created by us. Promises loaded from JavaScript (even if they were originally created by us) can't call this.

Definition at line 101 of file promise.cc.

§ Then()

void shaka::Promise::Then ( std::function< void(Any)>  on_resolve,
std::function< void(Any)>  on_reject 
)

Adds callbacks that are invoked once this Promise is resolved/rejected. These are called on the event thread. Like in JavaScript, if the Promise is already resolved/rejected, these will be called on the next loop.

Definition at line 139 of file promise.cc.

§ ToJsValue()

ReturnVal< JsValue > shaka::Promise::ToJsValue ( ) const
overridevirtual

Converts the current value into a JavaScript value.

Implements shaka::GenericConverter.

Definition at line 87 of file promise.cc.

§ Trace()

void shaka::Promise::Trace ( memory::HeapTracer tracer) const
overridevirtual

Called during a GC run. This should call HeapTracer::Trace on all Traceable members. Be sure to call the base method when overriding.

Implements shaka::memory::Traceable.

Definition at line 91 of file promise.cc.

§ TryConvert()

bool shaka::Promise::TryConvert ( Handle< JsValue >  value)
overridevirtual

Tries to convert the given value into the required type, populating the members of this object as needed.

Returns
True on success, false on error.

Implements shaka::GenericConverter.

Definition at line 73 of file promise.cc.


The documentation for this class was generated from the following files: