vladopajic / go-actor Goto Github PK
View Code? Open in Web Editor NEWA tiny library for writing concurrent programs in Go using actor model
License: MIT License
A tiny library for writing concurrent programs in Go using actor model
License: MIT License
What are some generic tests which could benefit any Actor/Worker implementation?
Idea of this issue is to explore those possibilities and create those utilities if any.
Hello,
very interesting project. I would like to give it a try and build something on it but i have a question, it seems to me that currently remote actors with message passing through e.g. rpc are not supported, is that correct?
So I was playing around with seeing if I can replicate the idea of a concurrent stream using the actor framework.
Consider the following code:
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/vladopajic/go-actor/actor"
)
type OutStream actor.Actor
// outstream worker
type OutStreamWorker struct {
mailbox actor.MailboxSender[string]
doFunc func() (string, bool)
}
func (w OutStreamWorker) DoWork(c actor.Context) actor.WorkerStatus {
val, ok := w.doFunc()
if ok {
w.mailbox.Send(c, val)
return actor.WorkerContinue
}
return actor.WorkerEnd
}
func NewOutStream(f func() (string, bool)) (OutStream, actor.Mailbox[string]) {
mailbox := actor.NewMailbox[string]()
worker := OutStreamWorker{
mailbox: mailbox,
doFunc: f,
}
actor := actor.New(worker)
return actor, mailbox
}
type strIter struct {
slice []string
cursor int
}
func (i *strIter) Next() (string, bool) {
if i.cursor < len(i.slice) {
val := i.slice[i.cursor]
i.cursor++
return val, true
} else {
return "", false
}
}
func main() {
iter := strIter{
slice: []string{"A", "B", "C"},
cursor: 0,
}
stream, mailbox := NewOutStream(iter.Next)
stream.Start()
for v := range mailbox.ReceiveC() {
fmt.Println(v)
}
}
The idea is the following: I create a stateful iterator with a .Next method, and then create an OutStream (which is just an actor) whose worker just takes the iterator and calls the .Next method and puts the results on the out mailbox. Then at the other end of the mailbox I just want to loop over the channel and print the results.
The above code blocks at w.mailbox.Send in the DoWork function, but my understanding was that mailbox should not block, any thoughts? :)
It looks like a lot of work went into this project, I'd love to be able to use it, and see other projects use it, too. Unfortunately, it's difficult to do so given the GPLv2 licensing. Would you consider relicensing the project under a permissive license such as the MIT, BSD, or Apache Software License?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.