HomePhabricator
Diffusion Comm 734a1b6e6a29

[native] RustPromiseManager

Description

[native] RustPromiseManager

Summary: In this diff, I've created a new singleton called RustPromiseManager. This singleton is responsible for keeping track of unresolved promises that depend on the execution of async Rust code, and for eventually rejecting or resolving the promises.

Test Plan: See the following diff

Reviewers: tomek, ashoat

Reviewed By: ashoat

Subscribers: jon, atul

Differential Revision: https://phab.comm.dev/D7113

Details

Provenance
varunAuthored on Mar 20 2023, 8:21 PM
Reviewer
ashoat
Differential Revision
D7113: [native] RustPromiseManager
Parents
rCOMMf55b55b3fef7: [native] render thread avatar in CHANNEL AVATAR thread settings section
Branches
Unknown
Tags
Unknown

Event Timeline

jon added inline comments.
/native/cpp/CommonCpp/NativeModules/InternalModules/RustPromiseManager.cpp
52

This will cause a dead lock if it ever executes as the lock isn't released in this block

/native/cpp/CommonCpp/NativeModules/InternalModules/RustPromiseManager.cpp
49

Should probably use lock_guard, so that the mutex is unlocked if the reference is dropped

https://en.cppreference.com/w/cpp/thread/lock_guard

ashoat added inline comments.
/native/cpp/CommonCpp/NativeModules/InternalModules/RustPromiseManager.cpp
52

I thought the lock is released when the lock object goes out-of-scope, which happens when the function returns. But I may have gotten myself confused – that might only work with lock_guard?

/native/cpp/CommonCpp/NativeModules/InternalModules/RustPromiseManager.cpp
52

It's dependent on what type you use, we are using a shared_ptr<share_mutex> here.

https://stackoverflow.com/questions/43019598/stdlock-guard-or-stdscoped-lock