nb architectural issues
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Refactor
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- rust
- Domain
- embedded-iot
Research direction
Start with the issue's send_something pseudocode and the documented serial_send and serial_receive examples. Investigate how nb functions preserve state across repeated WouldBlock returns and how stateful asynchronous work should be represented. Done means the architectural concern has an agreed API-level resolution or an explicit rationale for the existing design.
Written by the indexing model from the issue text.
Description
I believe there is a problem with the design of nb as it only allows for "one level" of asynchronicity, which is glossed over via the stubbed out definitions for the sample APIs in the documentation (such as serial_send and serial_receive).
If you were to actually flesh out those examples into real-world code, a problem arises wherein a nb function can really only decide that it would block once and only once. The moment stateful work commences that is predicated on the values that were passed in to the function, it becomes impossible to "early out" for the remainder of the function while still supporting a level of abstraction in which the function itself does not need to know anything about the caller.
For example, take the following pseudocode:
fn send_something(&mut self, bytes: &[u8]) -> nb::Result<(), !> {
let result = self.already_sending_something.compare_exchange(false, true, Ordering:..);
if result != Ok(false) {
// Awesome, we avoided blocking when the sender was busy
return Err(nb::Error::WouldBlock);
}
for i in 0..bytes.len() {
// Start sending by loading this byte into the send register
self.send_register.load(bytes[i]);
// We could poll until the byte has been sent
// while !self.send_register.is_empty() {};
// But why don't we avoid blocking instead?
if !self.send_register.is_empty() {
return nb::Error::WouldBlock;
}
}
return Ok(());
}
This code can be adapted to store i internally (saving state) so that the next time it is called after self.send_register.is_empty() returns false, it can pick up where it left off instead of starting over from zero, no problem. But how does it know that it is being called again by the same line of code/state?
- Dominant language
- Rust
- Stars
- 109
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-embedded/nb
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
rust-embedded/nb#37 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
rust-embedded/nb#17 · 1 comment ·
-
discussion
Difficulty 5/5 Over a week Newbie friendliness 25/100
rust-embedded/nb#16 · 2 comments · 1 reaction ·
-
discussion
Difficulty 5/5 Over a week Newbie friendliness 20/100
rust-embedded/nb#14 · 8 comments · 4 reactions ·
-
discussion
Difficulty 5/5 Over a week Newbie friendliness 25/100
rust-embedded/nb#13 · 5 comments ·
All issues in rust-embedded/nb
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100