func (App) Open(filepath string) circuit.X { f, err := os.Open(filepath) if err != nil { return nil } circuit.RunInBack(func() { time.Sleep(5 * time.Second) }) return circuit.Ref(file.NewFileServer(f)) }
// StartReducer.Start is a worker function that initializes a new Reducer and // returns a cross-runtime pointer to it func (StartReducer) Start() circuit.X { r := &Reducer{} // Create a new reducer object r.m = make(map[int64]*Post) // Create the map holding the posts, indexed by ID circuit.Listen("reducer-service", r) // Register Reducer as public service that can be accessed on this worker circuit.Daemonize(func() { r.maintainTop() // Start a background goroutine that maintains the top ten posts on this reducer }) return circuit.Ref(r) // Make the pointer to the Reducer object exportable and return it }
func (StartReducer) Start() circuit.X { r := &Reducer{} r.m = make(map[int64]*SlidingPost) r.rank = llrb.New(SlidingPostLess) circuit.Listen("reducer-service", r) circuit.Daemonize(func() { r.maintainTop() }) return circuit.Ref(r) }
// JailTail opens a file within this worker's jail directory and prepares a // cross-circuit pointer to the open file func (a *Acid) JailTail(jailFile string) (circuit.X, error) { abs := path.Join(config.Config.Deploy.JailDir(), circuit.WorkerAddr().WorkerID().String(), jailFile) cmd := exec.Command("/bin/sh", "-c", "tail -f "+abs) stdout, err := cmd.StdoutPipe() if err != nil { return nil, circuit.FlattenError(err) } if err = cmd.Start(); err != nil { return nil, circuit.FlattenError(err) } return circuit.Ref(teleio.NewServer(&tailStdout{stdout, cmd})), nil }
func spark(ch chan int) { d := &worker.Dummy{} runtime.SetFinalizer(d, func(h *worker.Dummy) { println("finalizing dummy") close(ch) }) defer runtime.GC() // Test: // Spawn a worker and pass an x-pointer to it; // Worker proceeds to die right away; // Check that finalizer of local dummy called when local runtime notices remote is dead _, addr, err := circuit.Spawn("localhost", []string{"/xgc"}, worker.Start{}, circuit.Ref(d)) if err != nil { panic(err) } println(addr.String()) }