-
-
Notifications
You must be signed in to change notification settings - Fork 119
api: cffi api to create account manager with existing events channel to see events emitted during startup. dc_event_channel_new, dc_event_channel_unref, dc_event_channel_get_event_emitter and dc_accounts_new_with_event_channel
#7609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api: cffi api to create account manager with existing events channel to see events emitted during startup. dc_event_channel_new, dc_event_channel_unref, dc_event_channel_get_event_emitter and dc_accounts_new_with_event_channel
#7609
Conversation
deltachat-ffi/deltachat.h
Outdated
| * Note: Use only one event emitter per account manager. | ||
| * Having more than one event emitter running at the same time on the same account manager | ||
| * will result in events randomly delivered to the one or to the other. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still the case?, rust code looks like it allows multiple listeners: it uses and async broadcast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it, probably it was forgotten in #5478 to update the documentation. But of course, the only way to be totally sure is actually trying it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deltachat-ffi/deltachat.h
Outdated
| * Create a new account manager with an existing events channel, | ||
| * which allows you see events emitted during startup. | ||
| * | ||
| * The account manager takes an directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * The account manager takes an directory | |
| * The account manager takes a directory |
Maybe it's better not to duplicate the documentation, but just add a reference to dc_account_new() and explain the difference. Otherwise API users need to read both and build a diff in their head, and we have more text to maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@r10s what's your opinion on references vs duplication in cffi docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it depends on amount of text. Huge texts should never be duplicated because users then have more work to read the docs and understand the difference between functions. E.g. see https://pubs.opengroup.org/onlinepubs/9799919799/functions/open.html, it documents two functions at the same time and explains which and when should be used, would be good if we can do the same, w/o duplication and extra cross-references.
EDIT: But i couldn't quickly find a way how to do this in Rust ideomatically.
e3d642b to
1541407
Compare
deltachat-ffi/src/lib.rs
Outdated
| use num_traits::{FromPrimitive, ToPrimitive}; | ||
| use tokio::runtime::Runtime; | ||
| use tokio::sync::RwLock; | ||
| use tokio::sync::{Mutex, RwLock}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need tokio mutex, just a std::sync::Mutex (or parking_lot::Mutex to avoid unwrap(), but then you need to add it as a dependency for deltachat_ffi). You call .blocking_lock() anyway.
See also https://docs.rs/tokio/latest/tokio/sync/struct.Mutex.html#which-kind-of-mutex-should-you-use, even in async code you don't necessarily need an async mutex.
see events emitted during startup. `dc_event_channel_new`, `dc_event_channel_unref`, `dc_event_channel_get_event_emitter` and `dc_accounts_new_with_event_channel`
bdbed25 to
6269889
Compare

closes #7606