Files
notedeck/crates/notedeck_columns/src/test_utils.rs
William Casarin 74c5f0c748 split notedeck into crates
This splits notedeck into crates, separating the browser chrome and
individual apps:

* notedeck: binary file, browser chrome
* notedeck_columns: our columns app
* enostr: same as before

We still need to do more work to cleanly separate the chrome apis
from the app apis. Soon I will create notedeck-notebook to see what
makes sense to be shared between the apps.

Some obvious ones that come to mind:

1. ImageCache

We will likely want to move this to the notedeck crate, as most apps
will want some kind of image cache. In web browsers, web pages do not
need to worry about this, so we will likely have to do something similar

2. Ndb

Since NdbRef is threadsafe and Ndb is an Arc<NdbRef>, it can be safely
copied to each app. This will simplify things. In the future we might
want to create an abstraction over this? Maybe each app shouldn't have
access to the same database... we assume the data in DBs are all public
anyways, but if we have unwrapped giftwraps that could be a problem.

3. RelayPool / Subscription Manager

The browser should probably maintain these. Then apps can use ken's
high level subscription manager api and not have to worry about
connection pool details

4. Accounts

Accounts and key management should be handled by the chrome. Apps should
only have a simple signer interface.

That's all for now, just something to think about!

Signed-off-by: William Casarin <jb55@jb55.com>
2024-12-11 11:24:29 -08:00

37 lines
1.4 KiB
Rust

use poll_promise::Promise;
use std::thread;
use std::time::Duration;
pub fn promise_wait<'a, T: Send + 'a>(promise: &'a Promise<T>) -> &'a T {
let mut count = 1;
loop {
if let Some(result) = promise.ready() {
println!("quieried promise num times: {}", count);
return result;
} else {
count += 1;
thread::sleep(Duration::from_millis(10));
}
}
}
/// `promise_assert` macro
///
/// This macro is designed to emulate the nature of immediate mode asynchronous code by repeatedly calling
/// promise.ready() for a promise, sleeping for a short period of time, and repeating until the promise is ready.
///
/// Arguments:
/// - `$assertion_closure`: the assertion closure which takes two arguments: the actual result of the promise and
/// the expected value. This macro is used as an assertion closure to compare the actual and expected values.
/// - `$expected`: The expected value of type `T` that the promise's result is compared against.
/// - `$asserted_promise`: A `Promise<T>` that returns a value of type `T` when the promise is satisfied. This
/// represents the asynchronous operation whose result will be tested.
///
#[macro_export]
macro_rules! promise_assert {
($assertion_closure:ident, $expected:expr, $asserted_promise:expr) => {
let result = $crate::test_utils::promise_wait($asserted_promise);
$assertion_closure!(*result, $expected);
};
}