Comments (4)
If I do understand you correctly... You are trying to create new gen.Server instance to start it under the Supervisor with the separated object under the hood for every single process. As you noticed, using the same object for that makes it shared between all the actors (processes spawned with this object). But... every process has a separate state which can be used within the process callbacks for your needs. Here is example
type private struct {
i int
}
type example struct {
gen.Server
shared int
}
func (e *example) Init(process *gen.ServerProcess, args ...etf.Term) error {
// State has interface{} type
process.State = &private{i: 123} // this value is only available for this process
e.shared = 567 // all spawned processes with the same object &example{...} have access to this value
return nil
}
func (e *example) HandleCast(process *gen.ServerProcess, message etf.Term) gen.ServerStatus {
state := process.State.(*private)
fmt.Printf("[%s] HandleCast: %#v\n", process.Name(), state)
return gen.ServerStatusOK
}
so, the answer is - this design is intentional
you may also want to see how to create a custom behavior on top of the gen.Server https://github.com/ergo-services/ergo/tree/master/examples/gendemo
from ergo.
Thanks for the example! Ok, I also know that process.State can be private, but I personally prefer private objects, temporary processes that access object code is easy to write and as friendly as an Erlang Dictionary! In this example, shared sharing also needs to be lock or unlocked during operation, but I don't like unlocking because I like Mailbox
from ergo.
I was thinking about your idea to create a new object for the spawned process. Pro - this object could be used as an atomic state. Cons - making a clone of provided object could be pretty hard and expensive (nested pointers, maps, slices, etc.).
from ergo.
I tried to solve this problem by dynamically starting and stopping the child spec.#140
from ergo.
Related Issues (20)
- How does ergo compare?
- GitHub actions fail on all platforms due to integration E2E tests HOT 1
- Unittest `TestDecodeFragment` occasionally fails
- i found rpc:call from erlang to ergo is not working HOT 2
- Ergo receives DIST packet along with the HANDSHAKE final packet. HOT 1
- Second CallRPC method is stuck when it is called against remote erlang node HOT 3
- Does Ergo have a plan to support OTP25/OTP26? HOT 1
- how to use simple_one_for_one under supervisor tree HOT 4
- Panic invalid memory address after reconnect a node HOT 6
- bug for deleteProcess HOT 3
- bug for (*process).UnregisterName HOT 2
- I doubt benchmarks be fair !!! HOT 3
- How to change Logger HOT 2
- gen.TcpHandle Question HOT 10
- When I close it frequently, there will be an unrecoverable panic. HOT 3
- Increase test coverage to 80% HOT 2
- node link problem? How to find HOT 8
- node link problem? HOT 2
- Support for Erlang/OTP 26 HOT 1
- Node.Stop () and node.Wait () will immediately end the process HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ergo.