Skip to content

Conversation

@Simon-Laux
Copy link
Member

@Simon-Laux Simon-Laux commented Dec 13, 2025

closes #7606

  • fix broken ci tests
  • test it manually

Comment on lines 6077 to 6080
* 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.
Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Member Author

@Simon-Laux Simon-Laux Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it, the assumption was correct: the comment is outdated, in cffi and rust api it is possible to have multiple event channels, only in jsonrpc api it is currently not possible.

image

* Create a new account manager with an existing events channel,
* which allows you see events emitted during startup.
*
* The account manager takes an directory
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.

Copy link
Member Author

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?

Copy link
Collaborator

@iequidoo iequidoo Dec 26, 2025

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.

@Simon-Laux Simon-Laux force-pushed the simon/i7606-cffi-api-to-create-event-emitter-before-account-manager branch from e3d642b to 1541407 Compare December 25, 2025 12:23
@Simon-Laux Simon-Laux requested a review from link2xt December 31, 2025 16:15
use num_traits::{FromPrimitive, ToPrimitive};
use tokio::runtime::Runtime;
use tokio::sync::RwLock;
use tokio::sync::{Mutex, RwLock};
Copy link
Collaborator

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.

@Simon-Laux Simon-Laux self-assigned this Jan 8, 2026
@Simon-Laux Simon-Laux force-pushed the simon/i7606-cffi-api-to-create-event-emitter-before-account-manager branch from bdbed25 to 6269889 Compare January 8, 2026 17:51
@Simon-Laux Simon-Laux merged commit fe6e942 into main Jan 8, 2026
30 checks passed
@Simon-Laux Simon-Laux deleted the simon/i7606-cffi-api-to-create-event-emitter-before-account-manager branch January 8, 2026 18:08
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.

Add CFFI API to create event emitter before account manager

5 participants