Files
herolib/libarchive/baobab/generator/templates/actor.v.template
2025-10-12 12:30:19 +03:00

42 lines
905 B
Plaintext

import os
import incubaid.herolib.baobab.stage
import incubaid.herolib.core.redisclient
import incubaid.herolib.schemas.openapi
import time
pub const configuration = stage.ActorConfig {
name: '@{name_snake}'
version: '@{version}'
}
@@[heap]
struct @{name_pascal}Actor {
stage.Actor
pub mut:
@{name_snake} I@{name_pascal}
}
pub fn new(core I@{name_pascal}, config stage.ActorConfig) !&@{name_pascal}Actor {
return &@{name_pascal}Actor {
Actor: stage.new_actor(config)!
@{name_snake}: core
}
}
pub fn (mut a @{name_pascal}Actor) handle(method string, data string) !string {
action := a.act(
name: method
params: data
)!
return action.result
}
// Actor listens to the Redis queue for method invocations
pub fn (mut a @{name_pascal}Actor) run() ! {
mut rpc := a.get_redis_rpc()!
for {
rpc.process(a.handle)!
time.sleep(time.millisecond * 100) // Prevent CPU spinning
}
}