[Proxying] Update proxying with callback to support cancellation - #18776
Conversation
| struct promise_result* info = malloc(sizeof(struct promise_result)); | ||
| if (!info) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Seems a little unfortunate to have to add an extra allocation here... but I guess it keeps the interface simpler?
| if (!info) { | ||
| return false; | ||
| } | ||
| *info = (struct promise_result){.promise = promise, .result = false}; |
There was a problem hiding this comment.
I think find it little more readable to just do:
info->promise = promise;
info->result = false;
Is the cast here actually needed? I guess so?
There was a problem hiding this comment.
Yeah, it's not actually a cast, but rather part of the compound literal syntax.
In general I prefer this syntax, but I agree that it's nice to give each field its own line. Maybe I'll try to tweak the clang format settings to make this nicer.
There was a problem hiding this comment.
It turns out that there's no clang-format setting for this, but putting a comma after the last item achieves the same thing.
There was a problem hiding this comment.
It just seems like more, and less obvious, syntax than the simple pair of assignments.. but maybe I'm just not familiar with reading code with this syntax.
|
This depends on #18741, by the way. |
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
741aafa to
b9fb8c0
Compare
f04027b to
60fd680
Compare
54d2274 to
d13a814
Compare
60fd680 to
2d74803
Compare
d13a814 to
1301f0e
Compare
848ee7d to
2213f1a
Compare
1301f0e to
c7918e5
Compare
2213f1a to
8b7eadf
Compare
c7918e5 to
5223090
Compare
8b7eadf to
d67be45
Compare
5223090 to
e0abb19
Compare
d67be45 to
aaa19c3
Compare
e0abb19 to
09a3df8
Compare
a1353b4 to
a5b591a
Compare
09a3df8 to
8b4eb90
Compare
a5b591a to
32309a3
Compare
8b4eb90 to
ea71ab3
Compare
32309a3 to
26bcd74
Compare
Completely overhaul the interface for proxying with callbacks: - Rename `emscripten_proxy_async_with_callback` to the simpler `emscripten_proxy_callback`. - Add an optional `cancel` callback argument that will be scheduled on the proxying thread if the worker thread dies before the work is started. A future PR will change this so that the `cancel` callback will be called if a worker thread dies before the work is finished to be more consistent with the `proxy_sync` APIs. - Remove the ability to receive the result of the proxied function as an argument to the callback function since the extra expressiveness was not general enough to warrant the added complexity. - Use only a single context argument rather than a separate context for the proxied function and the callback. This is just as expressive, but it is simpler avoids the question of what context object should be passed to the cancellation callback. Also update the only user of the callback API, dynlink.c, to use the new API. A future PR will implement a promise-based proxying API and update dynlink.c to use that instead, so this PR just tries to make the minimal necessary changes to dynlink.c.
26bcd74 to
413728b
Compare
…cripten-core#18776) Completely overhaul the interface for proxying with callbacks: - Rename `emscripten_proxy_async_with_callback` to the simpler `emscripten_proxy_callback`. - Add an optional `cancel` callback argument that will be scheduled on the proxying thread if the worker thread dies before the work is started. A future PR will change this so that the `cancel` callback will be called if a worker thread dies before the work is finished to be more consistent with the `proxy_sync` APIs. - Remove the ability to receive the result of the proxied function as an argument to the callback function since the extra expressiveness was not general enough to warrant the added complexity. - Use only a single context argument rather than a separate context for the proxied function and the callback. This is just as expressive, but it is simpler avoids the question of what context object should be passed to the cancellation callback. Also update the only user of the callback API, dynlink.c, to use the new API. A future PR will implement a promise-based proxying API and update dynlink.c to use that instead, so this PR just tries to make the minimal necessary changes to dynlink.c.
…cripten-core#18776) Completely overhaul the interface for proxying with callbacks: - Rename `emscripten_proxy_async_with_callback` to the simpler `emscripten_proxy_callback`. - Add an optional `cancel` callback argument that will be scheduled on the proxying thread if the worker thread dies before the work is started. A future PR will change this so that the `cancel` callback will be called if a worker thread dies before the work is finished to be more consistent with the `proxy_sync` APIs. - Remove the ability to receive the result of the proxied function as an argument to the callback function since the extra expressiveness was not general enough to warrant the added complexity. - Use only a single context argument rather than a separate context for the proxied function and the callback. This is just as expressive, but it is simpler avoids the question of what context object should be passed to the cancellation callback. Also update the only user of the callback API, dynlink.c, to use the new API. A future PR will implement a promise-based proxying API and update dynlink.c to use that instead, so this PR just tries to make the minimal necessary changes to dynlink.c.
|
Also, changelog of this seems to be written to 3.1.32 instead of correct 3.1.33 |
|
@DreamOfIce, if you reserve space for the result in the memory block you pass as the |
Thanks for catching that. I'll fix it. |
PR #18776 updated the changelog for 3.1.32, but it should have updated the changelog for 3.1.33, which was in development at the time.
PR #18776 updated the changelog for 3.1.32, but it should have updated the changelog for 3.1.33, which was in development at the time.
|
Also, any progress on the promise based proxy API yet? Is the promise here in js or cpp? |
|
@DreamOfIce, yes, you can see it here: https://github.com/emscripten-core/emscripten/blob/main/system/include/emscripten/proxying.h#L106-L116. Note that there is no documentation yet, because it relies on the promise API in promise.h, which isn't finished yet. There's also no C++ wrapper for |
|
In that case, I'll go ahead and use the version I implemented before |

Completely overhaul the interface for proxying with callbacks:
Rename
emscripten_proxy_async_with_callbackto the simpleremscripten_proxy_callback.Add an optional
cancelcallback argument that will be scheduled on the proxying thread if the worker thread dies before the work is started. A future PR will change this so that thecancelcallback will be called if a worker thread dies before the work is finished to be more consistent with theproxy_syncAPIs.Remove the ability to receive the result of the proxied function as an argument to the callback function since the extra expressiveness was not general enough to warrant the added complexity.
Use only a single context argument rather than a separate context for the proxied function and the callback. This is just as expressive, but it is simpler avoids the question of what context object should be passed to the cancellation callback.
Also update the only user of the callback API, dynlink.c, to use the new API. A future PR will implement a promise-based proxying API and update dynlink.c to use that instead, so this PR just tries to make the minimal necessary changes to dynlink.c.