Xonotic
promise.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define Promise_catch(this, handler, userdata)   Promise_catch_(this, Promise_new(), handler, userdata)
 
#define Promise_new()   Promise_new_(new_pure(Promise))
 
#define Promise_then(this, handler, userdata)   Promise_then_(this, Promise_new(), handler, userdata)
 

Functions

 entityclass (Promise)
 
Promise Promise_catch_ (Promise this, Promise ret, Promise(Promise ret, entity err, entity userdata) handler, entity userdata)
 
Promise Promise_new_ (Promise this)
 
void Promise_reject (Promise this)
 notify all Promise_catch subscribers that this promise has rejected More...
 
void Promise_resolve (Promise this)
 notify all Promise_then subscribers that this promise has resolved More...
 
Promise Promise_sleep (float n)
 
Promise Promise_then_ (Promise this, Promise ret, Promise(Promise ret, entity result, entity userdata) handler, entity userdata)
 

Macro Definition Documentation

◆ Promise_catch

#define Promise_catch (   this,
  handler,
  userdata 
)    Promise_catch_(this, Promise_new(), handler, userdata)

Definition at line 21 of file promise.qh.

◆ Promise_new

#define Promise_new ( )    Promise_new_(new_pure(Promise))

Definition at line 5 of file promise.qh.

Referenced by Promise_sleep().

◆ Promise_then

#define Promise_then (   this,
  handler,
  userdata 
)    Promise_then_(this, Promise_new(), handler, userdata)

Definition at line 13 of file promise.qh.

Function Documentation

◆ entityclass()

entityclass ( Promise  )

◆ Promise_catch_()

Promise Promise_catch_ ( Promise  this,
Promise  ret,
Promise(Promise ret, entity err, entity userdata)  handler,
entity  userdata 
)

◆ Promise_new_()

Promise Promise_new_ ( Promise  this)

Definition at line 51 of file promise.qc.

References _Promise_finalize(), _Promise_handle(), and ref_init().

52 {
53  ref_init(this, 2, _Promise_finalize);
54  this._promise_result = this; // promises default to being their own result to save on entities
55  return this;
56 }
void ref_init(entity this, int init, void(entity this) finalize)
Definition: promise.qc:6
void _Promise_finalize(Promise this)
Definition: promise.qc:46
+ Here is the call graph for this function:

◆ Promise_reject()

void Promise_reject ( Promise  this)

notify all Promise_catch subscribers that this promise has rejected

Definition at line 79 of file promise.qc.

References _Promise_handle(), _Promise_then(), entity(), IL_DELETE, IL_EACH, LOG_SEVERE, LOG_SEVEREF, PROMISE_PENDING, PROMISE_REJECTED, and unref().

Referenced by _Promise_onReject_default().

80 {
81  if (!this) {
82  LOG_SEVERE("Attempted to reject a null promise");
83  return;
84  }
85  if (this._promise_state != PROMISE_PENDING) {
86  LOG_SEVEREF("Rejected non-pending promise %i", this);
87  return;
88  }
89  this._promise_state = PROMISE_REJECTED;
90  if (this._promise_handlers) {
91  IL_EACH(this._promise_handlers, true, _Promise_handle(this, it));
92  IL_DELETE(this._promise_handlers);
93  }
94  unref(this);
95  return;
96 }
#define IL_EACH(this, cond, body)
entity unref(Promise this)
Definition: promise.qc:19
void _Promise_handle(Promise this, PromiseHandler h)
Definition: promise.qc:106
#define LOG_SEVEREF(...)
Definition: log.qh:63
#define IL_DELETE(this)
Delete the list.
#define LOG_SEVERE(...)
Definition: log.qh:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Promise_resolve()

void Promise_resolve ( Promise  this)

notify all Promise_then subscribers that this promise has resolved

Definition at line 60 of file promise.qc.

References _Promise_handle(), IL_DELETE, IL_EACH, LOG_SEVERE, LOG_SEVEREF, PROMISE_PENDING, PROMISE_RESOLVED, and unref().

Referenced by _Promise_onResolve_default(), and Promise_sleep().

61 {
62  if (!this) {
63  LOG_SEVERE("Attempted to resolve a null promise");
64  return;
65  }
66  if (this._promise_state != PROMISE_PENDING) {
67  LOG_SEVEREF("Resolved non-pending promise %i", this);
68  return;
69  }
70  this._promise_state = PROMISE_RESOLVED;
71  if (this._promise_handlers) {
72  IL_EACH(this._promise_handlers, true, _Promise_handle(this, it));
73  IL_DELETE(this._promise_handlers);
74  }
75  unref(this);
76  return;
77 }
#define IL_EACH(this, cond, body)
entity unref(Promise this)
Definition: promise.qc:19
void _Promise_handle(Promise this, PromiseHandler h)
Definition: promise.qc:106
#define LOG_SEVEREF(...)
Definition: log.qh:63
#define IL_DELETE(this)
Delete the list.
#define LOG_SEVERE(...)
Definition: log.qh:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Promise_sleep()

Promise Promise_sleep ( float  n)

Definition at line 206 of file promise.qc.

References Promise_new, Promise_resolve(), setthink, time, and unref().

207 {
208  Promise p = unref(Promise_new());
210  p.nextthink = time + n;
211  return p;
212 }
entity unref(Promise this)
Definition: promise.qc:19
#define Promise_new()
Definition: promise.qh:5
#define setthink(e, f)
float time
Definition: csprogsdefs.qc:16
void Promise_resolve(Promise this)
notify all Promise_then subscribers that this promise has resolved
Definition: promise.qc:60
+ Here is the call graph for this function:

◆ Promise_then_()

Promise Promise_then_ ( Promise  this,
Promise  ret,
Promise(Promise ret, entity result, entity userdata)  handler,
entity  userdata 
)

Definition at line 180 of file promise.qc.

References _Promise_then(), func_null(), and unref().

186 {
187  unref(ret); // ret is a temporary
188  return _Promise_then(this, ret, onResolve, func_null, userdata);
189 }
entity unref(Promise this)
Definition: promise.qc:19
Promise _Promise_then(Promise this, Promise ret, Promise(Promise ret, entity result, entity userdata) onResolve, Promise(Promise ret, entity result, entity userdata) onReject, entity userdata)
Definition: promise.qc:162
var void func_null()
+ Here is the call graph for this function: