Skip to content

Commit 43608a9

Browse files
1 parent 6803206 commit 43608a9

8 files changed

Lines changed: 101 additions & 100 deletions

File tree

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ representative at an online or offline event.
7373

7474
Instances of abusive, harassing, or otherwise unacceptable behavior may be
7575
reported to the community leaders responsible for enforcement at
76-
Community@Editor.Land. All complaints will be reviewed and investigated
77-
promptly and fairly. All community leaders are obligated to respect the privacy
78-
and security of the reporter of any incident.
76+
Community@Editor.Land. All complaints will be reviewed and investigated promptly
77+
and fairly. All community leaders are obligated to respect the privacy and
78+
security of the reporter of any incident.
7979

8080
## Enforcement Guidelines
8181

Example/Common/Read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Define actions for file reading and writing
2-
pub async fn Fn(Argument: Vec<Value>) -> Result<Value, Error> {
2+
pub async fn Fn(Argument:Vec<Value>) -> Result<Value, Error> {
33
let mut Content = String::new();
44

55
File::open(Argument[0].as_str().ok_or(Error::Execution("Invalid file path".to_string()))?)

Example/Common/Write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub async fn Fn(Argument: Vec<Value>) -> Result<Value, Error> {
1+
pub async fn Fn(Argument:Vec<Value>) -> Result<Value, Error> {
22
OpenOptions::new()
33
.write(true)
44
.create(true)

Example/Sequence.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ struct SimpleSite;
55

66
#[async_trait::async_trait]
77
impl Site for SimpleSite {
8-
async fn Receive(
9-
&self,
10-
Action: Box<dyn Echo::Trait::Sequence::Action::Trait>,
11-
Context: &Life,
12-
) -> Result<(), Error> {
8+
async fn Receive(&self, Action:Box<dyn Echo::Trait::Sequence::Action::Trait>, Context:&Life) -> Result<(), Error> {
139
Action.Execute(Context).await
1410
}
1511
}
@@ -19,8 +15,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
1915
// Create a plan with file reading and writing actions
2016
let Plan = Arc::new(
2117
Echo::Struct::Sequence::Plan::Struct::New()
22-
.WithSignature(Signature { Name: "Read".to_string() })
23-
.WithSignature(Signature { Name: "Write".to_string() })
18+
.WithSignature(Signature { Name:"Read".to_string() })
19+
.WithSignature(Signature { Name:"Write".to_string() })
2420
.WithFunction("Read", Common::Read::Fn)?
2521
.WithFunction("Write", Common::Write::Fn)?
2622
.Build(),
@@ -31,10 +27,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3127

3228
// Create a life context
3329
let Life = Life {
34-
Span: Arc::new(DashMap::new()),
35-
Fate: Arc::new(config::Config::default()),
36-
Cache: Arc::new(tokio::sync::Mutex::new(DashMap::new())),
37-
Karma: Arc::new(DashMap::new()),
30+
Span:Arc::new(DashMap::new()),
31+
Fate:Arc::new(config::Config::default()),
32+
Cache:Arc::new(tokio::sync::Mutex::new(DashMap::new())),
33+
Karma:Arc::new(DashMap::new()),
3834
};
3935

4036
// Create a site

Example/Tauri.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct SimpleSite;
44

55
#[async_trait::async_trait]
66
impl Site for SimpleSite {
7-
async fn Receive(&self, Action: Box<dyn Sequence::Action::Trait>, Context: &Life) -> Result<(), Error> {
7+
async fn Receive(&self, Action:Box<dyn Sequence::Action::Trait>, Context:&Life) -> Result<(), Error> {
88
Action.Execute(Context).await
99
}
1010
}
@@ -13,8 +13,8 @@ impl Site for SimpleSite {
1313
async fn main() -> Result<(), Box<dyn std::error::Error>> {
1414
let Plan = Arc::new(
1515
Echo::Struct::Sequence::Plan::Struct::New()
16-
.WithSignature(Action::Signature::Struct { Name: "Read".to_string() })
17-
.WithSignature(Action::Signature::Struct { Name: "Write".to_string() })
16+
.WithSignature(Action::Signature::Struct { Name:"Read".to_string() })
17+
.WithSignature(Action::Signature::Struct { Name:"Write".to_string() })
1818
.WithFunction("Read", Common::Read::Fn)?
1919
.WithFunction("Write", Common::Write::Fn)?
2020
.Build(),
@@ -23,10 +23,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2323
let Production = Arc::new(Echo::Struct::Sequence::Production::Struct::New());
2424

2525
let Life = Life {
26-
Span: Arc::new(dashmap::DashMap::new()),
27-
Fate: Arc::new(config::Config::default()),
28-
Cache: Arc::new(tokio::sync::Mutex::new(dashmap::DashMap::new())),
29-
Karma: Arc::new(dashmap::DashMap::new()),
26+
Span:Arc::new(dashmap::DashMap::new()),
27+
Fate:Arc::new(config::Config::default()),
28+
Cache:Arc::new(tokio::sync::Mutex::new(dashmap::DashMap::new())),
29+
Karma:Arc::new(dashmap::DashMap::new()),
3030
};
3131

3232
let Site = Arc::new(SimpleSite);

Example/WorkSteal.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
// Define a worker-stealing queue
44
struct WorkerStealingQueue {
5-
Queues: Vec<Arc<Mutex<Vec<Box<dyn Echo::Trait::Sequence::Action::Trait>>>>>,
5+
Queues:Vec<Arc<Mutex<Vec<Box<dyn Echo::Trait::Sequence::Action::Trait>>>>>,
66
}
77

88
impl WorkerStealingQueue {
9-
fn New(Force: usize) -> Self {
10-
WorkerStealingQueue { Queues: (0..Force).map(|_| Arc::new(Mutex::new(Vec::new()))).collect() }
9+
fn New(Force:usize) -> Self {
10+
WorkerStealingQueue { Queues:(0..Force).map(|_| Arc::new(Mutex::new(Vec::new()))).collect() }
1111
}
1212

13-
async fn Assign(&self, Identifier: usize, Action: Box<dyn Echo::Trait::Sequence::Action::Trait>) {
13+
async fn Assign(&self, Identifier:usize, Action:Box<dyn Echo::Trait::Sequence::Action::Trait>) {
1414
self.Queues[Identifier].lock().await.push(Action);
1515
}
1616

17-
async fn Do(&self, Worker: usize) -> Option<Box<dyn Echo::Trait::Sequence::Action::Trait>> {
17+
async fn Do(&self, Worker:usize) -> Option<Box<dyn Echo::Trait::Sequence::Action::Trait>> {
1818
let mut Queue = self.Queues[Worker].lock().await;
1919

2020
if let Some(Action) = Queue.pop() {
@@ -23,7 +23,7 @@ impl WorkerStealingQueue {
2323
// Try to steal from other queues
2424
drop(Queue);
2525

26-
let mut QueuesOther: Vec<usize> = (0..self.Queues.len()).filter(|&i| i != Worker).collect();
26+
let mut QueuesOther:Vec<usize> = (0..self.Queues.len()).filter(|&i| i != Worker).collect();
2727

2828
QueuesOther.shuffle(&mut rand::thread_rng());
2929

@@ -42,24 +42,20 @@ impl WorkerStealingQueue {
4242

4343
// Define a worker that implements the Worker trait
4444
struct StealingWorker {
45-
Id: usize,
46-
Queue: Arc<WorkerStealingQueue>,
45+
Id:usize,
46+
Queue:Arc<WorkerStealingQueue>,
4747
}
4848

4949
#[async_trait]
5050
impl Worker for StealingWorker {
51-
async fn Receive(
52-
&self,
53-
Action: Box<dyn Echo::Trait::Sequence::Action::Trait>,
54-
Context: &Life,
55-
) -> Result<(), Error> {
51+
async fn Receive(&self, Action:Box<dyn Echo::Trait::Sequence::Action::Trait>, Context:&Life) -> Result<(), Error> {
5652
self.Queue.Assign(self.Id, Action).await;
5753

5854
Ok(())
5955
}
6056
}
6157

62-
async fn worker_loop(Worker: Arc<StealingWorker>, Life: Arc<Life>, Running: Arc<Mutex<bool>>) {
58+
async fn worker_loop(Worker:Arc<StealingWorker>, Life:Arc<Life>, Running:Arc<Mutex<bool>>) {
6359
while *Running.lock().await {
6460
if let Some(Action) = Worker.Queue.Do(Worker.Id).await {
6561
if let Err(_Error) = Action.Execute(&Life).await {
@@ -76,8 +72,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7672
// Create a plan with file reading and writing actions
7773
let Plan = Arc::new(
7874
Echo::Struct::Sequence::Plan::Struct::New()
79-
.WithSignature(Signature { Name: "Read".to_string() })
80-
.WithSignature(Signature { Name: "Write".to_string() })
75+
.WithSignature(Signature { Name:"Read".to_string() })
76+
.WithSignature(Signature { Name:"Write".to_string() })
8177
.WithFunction("Read", Common::Read::Fn)?
8278
.WithFunction("Write", Common::Write::Fn)?
8379
.Build(),
@@ -90,22 +86,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
9086

9187
// Create a life context
9288
let Life = Arc::new(Life {
93-
Span: Arc::new(dashmap::DashMap::new()),
94-
Fate: Arc::new(config::Config::default()),
95-
Cache: Arc::new(tokio::sync::Mutex::new(dashmap::DashMap::new())),
96-
Karma: Arc::new(dashmap::DashMap::new()),
89+
Span:Arc::new(dashmap::DashMap::new()),
90+
Fate:Arc::new(config::Config::default()),
91+
Cache:Arc::new(tokio::sync::Mutex::new(dashmap::DashMap::new())),
92+
Karma:Arc::new(dashmap::DashMap::new()),
9793
});
9894

9995
// Create workers
100-
let Workers: Vec<Arc<StealingWorker>> = (0..Force)
101-
.map(|Id| Arc::new(StealingWorker { Id, Queue: Queue.clone() }))
96+
let Workers:Vec<Arc<StealingWorker>> = (0..Force)
97+
.map(|Id| Arc::new(StealingWorker { Id, Queue:Queue.clone() }))
10298
.collect();
10399

104100
// Create a flag to control worker loops
105101
let Running = Arc::new(Mutex::new(true));
106102

107103
// Spawn worker tasks
108-
let Handle: Vec<_> = Workers
104+
let Handle:Vec<_> = Workers
109105
.iter()
110106
.map(|Worker| {
111107
let Worker = Worker.clone();

Knowledge.dot

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
digraph G {
2-
newrank=true;
3-
rankdir=LR;
4-
splines=ortho;
5-
overlap=false;
6-
nodesep=0.5;
7-
ranksep=0.5;
8-
concentrate=true;
9-
graph [bgcolor="#f9f9f9", color="#888888", penwidth=2, fontname="Arial"];
10-
node [fontname="Arial", fontsize=14, style=filled, margin="0.3,0.2"];
11-
edge [fontname="Arial", fontsize=10, color="#555555", fontcolor="gray"];
12-
subgraph cluster_1 {
13-
label="root";
14-
style=filled; color="#5DADE2"; fillcolor="#5DADE220";
15-
"n0" [label="root", shape=folder, fillcolor="#5DADE2", penwidth=1.5];
16-
"n4" [label="npm (.): @codeeditorland/echo v0.0.1", shape=ellipse, fillcolor="#F4D03F", penwidth=1.5];
17-
"n3" [label="cargo (.): Echo v0.0.1", shape=ellipse, fillcolor="#EB984E", penwidth=1.5];
18-
"n2" [label="package.json", shape=note, fillcolor="#FADBD8", penwidth=1];
19-
"n1" [label="Cargo.toml", shape=note, fillcolor="#FADBD8", penwidth=1];
20-
}
21-
22-
"n0" -> "n1" [label="Contain", style=solid, color="blue", weight=2, arrowsize=0.8];
23-
"n0" -> "n2" [label="Contain", style=solid, color="blue", weight=2, arrowsize=0.8];
24-
"n0" -> "n3" [label="Contain", style=solid, color="blue", weight=2, arrowsize=0.8];
25-
"n0" -> "n4" [label="Contain", style=solid, color="blue", weight=2, arrowsize=0.8];
26-
subgraph cluster_legend {
27-
label="Legend"; fontsize=14; style=dashed; color=gray;
28-
"dir" [label="Directory", shape=folder, fillcolor="#5DADE2"];
29-
"file" [label="File", shape=note, fillcolor="#FADBD8"];
30-
"pkg" [label="Package", shape=ellipse, fillcolor="#EB984E"];
31-
"ext" [label="External", shape=trapezium, fillcolor="#EC7063"];
32-
"dir" -> "file" [label="Contain", style=solid, color=blue];
33-
"pkg" -> "ext" [label="Dependency", style=dashed, color=red];
34-
}
2+
newrank = true;
3+
rankdir = LR;
4+
splines = ortho;
5+
overlap = false;
6+
nodesep = 0.5;
7+
ranksep = 0.5;
8+
concentrate = true;
9+
graph [bgcolor = "#f9f9f9"; color = "#888888"; penwidth = 2; fontname = "Arial";];
10+
node [fontname = "Arial"; fontsize = 14; style = filled; margin = "0.3,0.2";];
11+
edge [fontname = "Arial"; fontsize = 10; color = "#555555"; fontcolor = "gray";];
12+
subgraph cluster_1 {
13+
label = "root";
14+
style = filled;
15+
color = "#5DADE2";
16+
fillcolor = "#5DADE220";
17+
"n0" [label = "root";shape = folder;fillcolor = "#5DADE2";penwidth = 1.5;];
18+
"n4" [label = "npm (.): @codeeditorland/echo v0.0.1";shape = ellipse;fillcolor = "#F4D03F";penwidth = 1.5;];
19+
"n3" [label = "cargo (.): Echo v0.0.1";shape = ellipse;fillcolor = "#EB984E";penwidth = 1.5;];
20+
"n2" [label = "package.json";shape = note;fillcolor = "#FADBD8";penwidth = 1;];
21+
"n1" [label = "Cargo.toml";shape = note;fillcolor = "#FADBD8";penwidth = 1;];
22+
}
23+
24+
"n0" -> "n1" [label = "Contain"; style = solid; color = "blue"; weight = 2; arrowsize = 0.8;];
25+
"n0" -> "n2" [label = "Contain"; style = solid; color = "blue"; weight = 2; arrowsize = 0.8;];
26+
"n0" -> "n3" [label = "Contain"; style = solid; color = "blue"; weight = 2; arrowsize = 0.8;];
27+
"n0" -> "n4" [label = "Contain"; style = solid; color = "blue"; weight = 2; arrowsize = 0.8;];
28+
subgraph cluster_legend {
29+
label = "Legend";
30+
fontsize = 14;
31+
style = dashed;
32+
color = gray;
33+
"dir" [label = "Directory";shape = folder;fillcolor = "#5DADE2";];
34+
"file" [label = "File";shape = note;fillcolor = "#FADBD8";];
35+
"pkg" [label = "Package";shape = ellipse;fillcolor = "#EB984E";];
36+
"ext" [label = "External";shape = trapezium;fillcolor = "#EC7063";];
37+
"dir" -> "file" [label = "Contain"; style = solid; color = blue;];
38+
"pkg" -> "ext" [label = "Dependency"; style = dashed; color = red;];
39+
}
3540
}

README.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,47 +161,51 @@ used throughout the application, often via a shared context or runtime.
161161
application starts. It is typically wrapped in an `Arc` to be shared safely
162162
across your application.
163163

164-
```rust
165-
// In your application's main function
166-
167-
use std::sync::Arc;
168-
use Echo::Scheduler::SchedulerBuilder;
169-
use Echo::Task::Priority;
164+
```rust
165+
166+
// In your application's main function
167+
168+
use std::sync::Arc;
169+
use Echo::Scheduler::SchedulerBuilder;
170+
use Echo::Task::Priority;
170171

171172
// Use the fluent builder to configure and build the scheduler
172-
173+
173174
let Scheduler = Arc::new(SchedulerBuilder::Create().WithWorkerCount(8).Build());
174175
```
175176

176177
2. **Submit Tasks:** Use the `Scheduler` instance to submit asynchronous work
177178
from anywhere in your application.
178179

179-
```rust
180-
// An example async block to be run by the scheduler
181-
182-
let MyTask = async {
183-
println!("This is running on an Echo worker thread!");
184-
// ... perform some work ...
185-
186-
};
180+
```rust
181+
182+
// An example async block to be run by the scheduler
183+
184+
let MyTask = async {
185+
println!("This is running on an Echo worker thread!");
186+
187+
// ... perform some work ...
188+
189+
};
187190

188191
// Submit the task with a desired priority
189-
192+
190193
Scheduler.Submit(MyTask, Priority::Normal);
191194

192195
// Another example with high priority
193-
196+
194197
Scheduler.Submit(async { /* critical work */ }, Priority::High);
195198
```
196199

197200
3. **Graceful Shutdown:** Before your application exits, ensure a clean
198201
shutdown of all worker threads.
199202

200-
```rust
201-
// In your application's shutdown sequence
202-
203+
```rust
204+
205+
// In your application's shutdown sequence
206+
203207
// Note: Arc::try_unwrap requires the Arc to have only one strong reference.
204-
208+
205209
if let Ok(mut Scheduler) = Arc::try_unwrap(Scheduler) {
206210
Scheduler.Stop().await;
207211
}

0 commit comments

Comments
 (0)