Skip to content

Conversation

@IdWV
Copy link
Contributor

@IdWV IdWV commented Jan 3, 2025

This library adds setTimout(), setInterval(), setImmediate(), clearTimeout(), Promise(), PromiseAll(), PromiseAny(), PromiseRace(), PromiseAllSettled(), throw(), uptime() and PumpEvents().

And it adds a c API to offload work to another thread. This is (partly) demonstrated in examples/async-worker.c. Further is adds a c API to call directly into the script from another thread. ('Alien' calls). This is demonstrated in examples/async-alien.c. This c API adds no link-time dependencies, everything is handled through a registry entry.

The script functions (are supposed to) behave the same as their ECMAscript counterparts, except throw(). throw() is a function, not a keyword.

I injected 1 inline function in uc_vm_execute() in libucode, after the central uc_vm_execute_chunk() to pump events until no more timers and promises are pending,

It's also possible to explicitly pump inside the script, using PumpEvents(), which in that case can also be used as delay() function.

IdWV added 13 commits January 3, 2025 12:21
with as extra above uc_cfunction_t a feedback function which is called on destruction, plus a way to allocate extra user bytes in the creator function.
This library adds setTimout(), setInterval(), setImmediate(), clearTimeout(), Promise(), PromiseAll(), PromiseAny(), PromiseRace(), PromiseAllSettled(), throw(), uptime() and PumpEvents().
And it adds a c API to offload work to another thread. This is (partly) demonstrated in examples/async-worker.c. Further is adds a c API to call directly into the script from another thread. ('Alien' calls). This is demonstrated in examples/async-alien.c. This c API adds no link-time dependencies, everything is handled through a registry entry.

The script functions (are supposed to) behave the same as their ECMAscript counterparts, except throw(). throw() is a function, not a keyword.

I injected 1 inline function in uc_vm_execute() in libucode, after the central uc_vm_execute_chunk() to pump events until no more timers and promises are pending,

It's also possible to explicitly pump inside the script, using PumpEvents(), which in that case can also be used as delay() function.
…declared as _Atomic, while this isn't needed (or forced) in gcc.
Remove unused inline function 'async_callback_queuer_cast()'.
@jow-
Copy link
Owner

jow- commented Jan 4, 2025

I see you introduced a new function type to achieve a closure with garbage collection.

I think we should extend the existing resource type to allow for callable values, e.g. by providing a call function through the prototype.

I’ll draft something and get back here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants