()
| 70 | } |
| 71 | |
| 72 | func (v *VM) Fork() *VM { |
| 73 | v.vmsMu.Lock() |
| 74 | defer v.vmsMu.Unlock() |
| 75 | newVM := &VM{ |
| 76 | o: v.o.Copy(), |
| 77 | vms: v.vms, |
| 78 | vmsMu: v.vmsMu, |
| 79 | disposables: make(map[any]struct{}), |
| 80 | } |
| 81 | newVM.o.Interrupt = make(chan func(), 1) |
| 82 | v.vms[newVM.o] = newVM |
| 83 | return newVM |
| 84 | } |
| 85 | |
| 86 | // resolveVM returns the *VM that owns the given otto runtime. Forks share a |
| 87 | // single vms map, so reads must be guarded against concurrent Fork/Dispose |