HxRefactored 2015: MediSafe "Cloud-Synced Medication Management for Patients and Their Caregivers"
My client wanted their apps synced, and I made it with Go
-
Upload
toru-furukawa -
Category
Software
-
view
991 -
download
1
Transcript of My client wanted their apps synced, and I made it with Go
![Page 1: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/1.jpg)
Myclientwantedtheirappssynced,andImadeitwithGo
@torufurukawaToruFurukawa
![Page 2: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/2.jpg)
Canyourunappsinparallel?
Yes,Iguess
![Page 3: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/3.jpg)
Iwillsendpurchaseorder.
![Page 4: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/4.jpg)
![Page 5: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/5.jpg)
Solversimulatesonly1Object
Solver(app/DLL)
Wrapperapp
![Page 6: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/6.jpg)
SimulaMngmulMpleobjectsserially
Solver
ControlWrapper Wrapper
Swapsinternalvariables
![Page 7: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/7.jpg)
Wanttoruntheminparallelandsynced
ControlWrapper Wrapper
Wrapper
Wrapper
(concurrent)
![Page 8: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/8.jpg)
Concurrency?Sync?Go!
hOps://talks.golang.org/2012/waza.slide#14
![Page 9: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/9.jpg)
• Concurrency• Messaging(dataexchange)• SynchronizaMon
![Page 10: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/10.jpg)
Process
Libmemory
DLLsimulatesanobject'sbehavior
DLL
Load
![Page 11: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/11.jpg)
DelegatesimulaMontoDLLfuncdll,err:=syscall.LoadDLL(path)
proc:=dll.MustFindProc("simulate")
...
for{
ret,_,err:=proc.Call(...)
ret!=0{
break
}
}
![Page 12: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/12.jpg)
MakeanotherDLLtocallsolverDLL
wrap_f(double*x){
*x=f();
}
Goapp
WrapperDLLwrap_f()
SolverDLLf()
![Page 13: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/13.jpg)
Process
Libmemory
ConcurrencyProcess
Libmemory
DLLfile
Load
Process
Libmemory
![Page 14: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/14.jpg)
Addmessagebroker
Process Process Process
MessageBroker
![Page 15: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/15.jpg)
Listen,AcceptandHandle
funcmain(){
...
ch:=make(chanevent)
golistenAndServe(ch,...)
...
}
![Page 16: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/16.jpg)
Listen,AcceptandHandlefunclistenAndServe(chanevent){
ln,err:=net.Listen(…)
for{
conn,err:=ln.Accept()
gohandleConn(conn,ch)
}
}
![Page 17: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/17.jpg)
HandleRequestsfunchandleConn(...){
for{
req:=read(conn)
respCh:=make(chan…)
ch<-event{req,
respCh}
resp:=<-respCh
write(conn,resp)
}
}
funcmain(){
…
for{
e:=<-ch
result=do(e.req)
e.respCh<-result
}
}
![Page 18: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/18.jpg)
Messaging
Process Process Process
MessageBroker
SET SET SET GET
![Page 19: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/19.jpg)
Needallprocessessynced
ProcessA
Time
ProcessB
ProcessC
![Page 20: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/20.jpg)
Suspendtaskifnotreadyfuncmain(){
...
for{
event:=<-ch
if!ready(event.req){
tasks=append(tasks,
func(){do(event.req)})
continue
}
result=do(event.req)
...
}
![Page 21: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/21.jpg)
Flushtaskswhenready
funcmain(){
...
ifreadyToFlush(...){
for_,t:=rangetasks{
t()
}
tasks:=make([]task,0)
}
...
}
![Page 22: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/22.jpg)
Sync
ProcessA
Time
ProcessB
ProcessC
![Page 23: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/23.jpg)
Concurrency?Sync?Go!
![Page 24: My client wanted their apps synced, and I made it with Go](https://reader031.fdocuments.net/reader031/viewer/2022030313/58e49b881a28aba3458b4fe7/html5/thumbnails/24.jpg)
Justshippedlastweek
@torufurukawa