4 .void(
entity this) _ref_finalize;
9 this._ref_finalize = finalize;
24 this._ref_finalize(
this);
38 classfield(Promise) .IntrusiveList _promise_handlers;
41 classfield(PromiseHandler) .Promise _promise_handler_ret;
42 classfield(PromiseHandler) .entity _promise_handler_data;
54 this._promise_result =
this;
63 LOG_SEVERE(
"Attempted to resolve a null promise");
67 LOG_SEVEREF(
"Resolved non-pending promise %i",
this);
71 if (this._promise_handlers) {
82 LOG_SEVERE(
"Attempted to reject a null promise");
86 LOG_SEVEREF(
"Rejected non-pending promise %i",
this);
90 if (this._promise_handlers) {
101 Promise(Promise ret,
entity result,
entity userdata) onResolve,
102 Promise(Promise ret,
entity result,
entity userdata) onReject,
108 switch (this._promise_state) {
110 if (!this._promise_handlers) {
111 this._promise_handlers =
IL_NEW();
113 IL_PUSH(this._promise_handlers, h);
116 Promise ret = h._promise_handler_ret;
117 Promise p = h._promise_handler_resolve(ret, this._promise_result, h._promise_handler_data);
123 Promise ret = h._promise_handler_ret;
124 Promise p = h._promise_handler_reject(ret, this._promise_result, h._promise_handler_data);
134 Promise(Promise ret,
entity result,
entity userdata) onResolve,
135 Promise(Promise ret,
entity err,
entity userdata) onReject,
140 PromiseHandler h =
new_pure(PromiseHandler);
141 h._promise_handler_ret = ret;
142 h._promise_handler_data = userdata;
143 h._promise_handler_resolve = onResolve;
144 h._promise_handler_reject = onReject;
150 ret._promise_result =
result;
157 ret._promise_result =
err;
165 Promise(Promise ret,
entity result,
entity userdata) onResolve,
166 Promise(Promise ret,
entity result,
entity userdata) onReject,
183 Promise(Promise ret,
entity result,
entity userdata) onResolve,
194 Promise(Promise ret,
entity result,
entity userdata) onReject,
210 p.nextthink =
time + n;
#define IL_EACH(this, cond, body)
entity unref(Promise this)
void Promise_reject(Promise this)
notify all Promise_catch subscribers that this promise has rejected
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)
void _Promise_handle(Promise this, PromiseHandler h)
classfield(Promise) .int _promise_state
string sourceLoc
Location entity was spawned from in source.
void ref_init(entity this, int init, void(entity this) finalize)
entity entity userdata _promise_handler_resolve
Promise _Promise_onResolve_default(Promise ret, entity result, entity userdata)
entity entity userdata _promise_handler_reject
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
Promise _Promise_onReject_default(Promise ret, entity err, entity userdata)
Promise Promise_sleep(float n)
entityclass(PromiseHandler)
void _Promise_finalize(Promise this)
#define IL_DELETE(this)
Delete the list.
Promise Promise_catch_(Promise this, Promise ret, Promise(Promise ret, entity result, entity userdata) onReject, entity userdata)
#define new_pure(class)
purely logical entities (.origin doesn't work)
Promise Promise_new_(Promise this)
void Promise_resolve(Promise this)
notify all Promise_then subscribers that this promise has resolved
Promise Promise_then_(Promise this, Promise ret, Promise(Promise ret, entity result, entity userdata) onResolve, entity userdata)
void _Promise_done(Promise this, Promise(Promise ret, entity result, entity userdata) onResolve, Promise(Promise ret, entity err, entity userdata) onReject, Promise ret, entity userdata)