Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
357d2cd0
Commit
357d2cd0
authored
5 months ago
by
Bernardo Cardoso
Browse files
Options
Downloads
Patches
Plain Diff
Allow APP to fully stop xxDK stop workers + unload Cmix state
parent
c04e6940
No related branches found
Branches containing commit
No related tags found
1 merge request
!143
Some changes for Phoenixx
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.go
+12
-0
12 additions, 0 deletions
main.go
wasm/cmix.go
+12
-0
12 additions, 0 deletions
wasm/cmix.go
worker/manager.go
+42
-0
42 additions, 0 deletions
worker/manager.go
with
66 additions
and
0 deletions
main.go
+
12
−
0
View file @
357d2cd0
...
...
@@ -22,6 +22,7 @@ import (
"gitlab.com/elixxir/xxdk-wasm/logging"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/wasm"
"gitlab.com/elixxir/xxdk-wasm/worker"
)
func
main
()
{
...
...
@@ -77,6 +78,13 @@ var wasmCmd = &cobra.Command{
},
}
func
stopWorkers
(
_
js
.
Value
,
_
[]
js
.
Value
)
any
{
// Stop all existing managers
jww
.
INFO
.
Printf
(
"Stopping xxDK WebAssembly workers..."
)
worker
.
Tracker
.
Stop
()
return
nil
}
// setGlobals enables all global functions to be accessible to Javascript.
func
setGlobals
()
{
jww
.
INFO
.
Printf
(
"Starting xxDK WebAssembly bindings."
)
...
...
@@ -166,6 +174,7 @@ func setGlobals() {
js
.
Global
()
.
Set
(
"LoadCmix"
,
js
.
FuncOf
(
wasm
.
LoadCmix
))
js
.
Global
()
.
Set
(
"LoadSynchronizedCmix"
,
js
.
FuncOf
(
wasm
.
LoadSynchronizedCmix
))
js
.
Global
()
.
Set
(
"UnloadCmix"
,
js
.
FuncOf
(
wasm
.
UnloadCmix
))
// wasm/delivery.go
js
.
Global
()
.
Set
(
"SetDashboardURL"
,
js
.
FuncOf
(
wasm
.
SetDashboardURL
))
...
...
@@ -272,6 +281,9 @@ func setGlobals() {
// wasm/rpc.go
js
.
Global
()
.
Set
(
"RPCSend"
,
js
.
FuncOf
(
wasm
.
RPCSend
))
// Stop all existing workers (except logfile worker)
js
.
Global
()
.
Set
(
"StopWorkers"
,
js
.
FuncOf
(
stopWorkers
))
}
var
(
...
...
This diff is collapsed.
Click to expand it.
wasm/cmix.go
+
12
−
0
View file @
357d2cd0
...
...
@@ -233,6 +233,18 @@ func LoadSynchronizedCmix(_ js.Value, args []js.Value) any {
return
utils
.
CreatePromise
(
promiseFn
)
}
// UnloadCmix will unload an existing cMix instance
//
// Parameters:
// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved
// using [Cmix.GetID].
//
// Returns error or nil
func
UnloadCmix
(
_
js
.
Value
,
args
[]
js
.
Value
)
any
{
cmixID
:=
args
[
0
]
.
Int
()
return
bindings
.
DeleteCmixInstance
(
cmixID
)
}
// GetID returns the ID for this [bindings.Cmix] in the cmixTracker.
//
// Returns:
...
...
This diff is collapsed.
Click to expand it.
worker/manager.go
+
42
−
0
View file @
357d2cd0
...
...
@@ -10,6 +10,7 @@
package
worker
import
(
"sync"
"syscall/js"
"time"
...
...
@@ -38,6 +39,45 @@ type Manager struct {
w
Worker
}
// Keep track of all managers created so that they can be stopped
// by the main WASM thread
type
ManagersTracker
struct
{
tracked
map
[
int
]
*
Manager
count
int
mux
sync
.
Mutex
}
// Only add managers locally
func
(
mt
*
ManagersTracker
)
add
(
m
*
Manager
)
{
mt
.
mux
.
Lock
()
defer
mt
.
mux
.
Unlock
()
id
:=
mt
.
count
mt
.
count
++
mt
.
tracked
[
id
]
=
m
}
// Stop all managers except logger
func
(
mt
*
ManagersTracker
)
Stop
()
{
mt
.
mux
.
Lock
()
defer
mt
.
mux
.
Unlock
()
for
id
,
m
:=
range
mt
.
tracked
{
name
:=
m
.
Name
()
if
name
==
"xxdkLogFileWorker-main"
{
// Don't stop the logfile manager
continue
}
m
.
Stop
()
delete
(
mt
.
tracked
,
id
)
}
}
var
Tracker
=
&
ManagersTracker
{
tracked
:
make
(
map
[
int
]
*
Manager
),
count
:
0
,
}
// NewManager generates a new Manager. This functions will only return once
// communication with the worker has been established.
func
NewManager
(
aURL
,
name
string
,
messageLogging
bool
)
(
*
Manager
,
error
)
{
...
...
@@ -58,6 +98,8 @@ func NewManager(aURL, name string, messageLogging bool) (*Manager, error) {
w
:
w
,
}
Tracker
.
add
(
m
)
// Register a callback that will receive initial message from worker
// indicating that it is ready
ready
:=
make
(
chan
struct
{})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment