Skip to content

Comments

Another mini sample to show starting two processes and discovery#1139

Open
ktoso wants to merge 1 commit intoapple:mainfrom
ktoso:wip-mini-sample
Open

Another mini sample to show starting two processes and discovery#1139
ktoso wants to merge 1 commit intoapple:mainfrom
ktoso:wip-mini-sample

Conversation

@ktoso
Copy link
Member

@ktoso ktoso commented Sep 21, 2023

To see this in action do:

swift run --package-path Samples/ SamplePair first

and in another process

swift run --package-path Samples/ SamplePair second

The actors discover and greet eachother then:

===-----------------------------------------------------===
|        Sample App Showing Two Actors Talking            |
|                                                         |
| USAGE: swift run SamplePair first|second                |
===-----------------------------------------------------===
[first-actor on sact://system@127.0.0.1:1111] Received message: Hello
from Person(/user/Person-b["$receptionID": "*", "$path":
/user/Person-b]) on sact://system@127.0.0.1:2222!
[first-actor on sact://system@127.0.0.1:1111] Found:
Person(sact://system@127.0.0.1:2222/user/Person-b)

Motivation:

An even more simple 2 process example to showcase discovery.

To see this in action do:

```
swift run --package-path Samples/ SamplePair first
```
and in another process

```
swift run --package-path Samples/ SamplePair second
```

The actors discover and greet eachother then:

```
===-----------------------------------------------------===
|        Sample App Showing Two Actors Talking            |
|                                                         |
| USAGE: swift run SamplePair first|second                |
===-----------------------------------------------------===
[first-actor on sact://system@127.0.0.1:1111] Received message: Hello
from Person(/user/Person-b["$receptionID": "*", "$path":
/user/Person-b]) on sact://system@127.0.0.1:2222!
[first-actor on sact://system@127.0.0.1:1111] Found:
Person(sact://system@127.0.0.1:2222/user/Person-b)

```
system.cluster.join(host: "127.0.0.1", port: firstPort)

try! await system.cluster.joined(within: .seconds(10))
let p = await Person(name: "first-actor", actorSystem: system)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess second-actor.

}

try? await Task.sleep(for: .seconds(60))
_ = p
Copy link

@lyzkov lyzkov Aug 5, 2024

Choose a reason for hiding this comment

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

_ = p changes nothing and means nothing, breaking Occam's Razor principle. The _ = p definition exists only to suppress compiler warnings. Are there any other ways of retaining Person instance without declaring an unused constant? autoreleasepool?

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.

3 participants