Skip to content
Snippets Groups Projects
Commit 568f76cb authored by Josh Brooks's avatar Josh Brooks
Browse files

Merge branch 'XX-4425/DummyMessagePauseAndResume' into 'release'

WIP: Add Resume/Pause bindings to Dummy

See merge request !55
parents da13202c e052a317
No related branches found
No related tags found
2 merge requests!60Revert "Fail a test to be sure it works",!55WIP: Add Resume/Pause bindings to Dummy
...@@ -26,7 +26,8 @@ type DummyTraffic struct { ...@@ -26,7 +26,8 @@ type DummyTraffic struct {
func newDummyTrafficJS(newDT *bindings.DummyTraffic) map[string]any { func newDummyTrafficJS(newDT *bindings.DummyTraffic) map[string]any {
dt := DummyTraffic{newDT} dt := DummyTraffic{newDT}
dtMap := map[string]any{ dtMap := map[string]any{
"SetStatus": js.FuncOf(dt.SetStatus), "Pause": js.FuncOf(dt.Pause),
"Start": js.FuncOf(dt.Start),
"GetStatus": js.FuncOf(dt.GetStatus), "GetStatus": js.FuncOf(dt.GetStatus),
} }
...@@ -34,11 +35,11 @@ func newDummyTrafficJS(newDT *bindings.DummyTraffic) map[string]any { ...@@ -34,11 +35,11 @@ func newDummyTrafficJS(newDT *bindings.DummyTraffic) map[string]any {
} }
// NewDummyTrafficManager creates a [DummyTraffic] manager and initialises the // NewDummyTrafficManager creates a [DummyTraffic] manager and initialises the
// dummy traffic sending thread. Note that the manager does not start sending // dummy traffic sending thread. Note that the manager is by default paused,
// dummy traffic until true is passed into [DummyTraffic.SetStatus]. The time // and as such the sending thread must be started by calling [DummyTraffic.Start].
// duration between each sending operation and the amount of messages sent each // The time duration between each sending operation and the amount of messages
// interval are randomly generated values with bounds defined by the given // sent each interval are randomly generated values with bounds defined by the
// parameters below. // given parameters below.
// //
// Parameters: // Parameters:
// - args[0] - A [Cmix] object ID in the tracker (int). // - args[0] - A [Cmix] object ID in the tracker (int).
...@@ -64,22 +65,34 @@ func NewDummyTrafficManager(_ js.Value, args []js.Value) any { ...@@ -64,22 +65,34 @@ func NewDummyTrafficManager(_ js.Value, args []js.Value) any {
return newDummyTrafficJS(dt) return newDummyTrafficJS(dt)
} }
// SetStatus sets the state of the [DummyTraffic] manager's send thread by // Pause will pause the [DummyTraffic]'s sending thread, meaning messages will no
// passing in a boolean parameter. There may be a small delay in between this // longer be sent. After calling Pause, the sending thread may only be resumed
// call and the status of the sending thread to change accordingly. For example, // by calling Resume.
// passing false into this call while the sending thread is currently sending
// messages will not cancel nor halt the sending operation, but will pause the
// thread once that operation has completed.
// //
// Parameters: // There may be a small delay between this call and the pause taking effect.
// - args[0] - Input should be true if you want to send dummy messages and // This is because Pause will not cancel the thread when it is in the process
// false if you want to pause dummy messages (boolean). // of sending messages, but will instead wait for that thread to complete. The
// thread will then be prevented from beginning another round of sending.
func (dt *DummyTraffic) Pause(js.Value, []js.Value) any {
err := dt.api.Pause()
if err != nil {
utils.Throw(utils.TypeError, err)
return nil
}
return nil
}
// Start will start up the [DummyTraffic]'s sending thread, meaning messages will
// be sent. This should be called after calling NewManager, as by default the
// thread is paused. This may also be called after a call to [DummyTraffic.Pause].
// //
// Returns: // This will re-initialize the sending thread with a new randomly generated
// - Throws a TypeError if the [DummyTraffic.SetStatus] is called too // interval between sending dummy messages. This means that there is zero
// frequently, causing the internal status channel to fill. // guarantee that the sending interval prior to pausing will be the same
func (dt *DummyTraffic) SetStatus(_ js.Value, args []js.Value) any { // sending interval after a call to Start.
err := dt.api.SetStatus(args[0].Bool()) func (dt *DummyTraffic) Start(js.Value, []js.Value) any {
err := dt.api.Start()
if err != nil { if err != nil {
utils.Throw(utils.TypeError, err) utils.Throw(utils.TypeError, err)
return nil return nil
...@@ -89,16 +102,14 @@ func (dt *DummyTraffic) SetStatus(_ js.Value, args []js.Value) any { ...@@ -89,16 +102,14 @@ func (dt *DummyTraffic) SetStatus(_ js.Value, args []js.Value) any {
} }
// GetStatus returns the current state of the [DummyTraffic] manager's sending // GetStatus returns the current state of the [DummyTraffic] manager's sending
// thread. Note that this function does not return the status set by the most // thread. Note that the status returned here may lag behind a user's earlier
// recent call to [DummyTraffic.SetStatus]. Instead, this call returns the // call to pause the sending thread. This is a result of a small delay (see
// current status of the sending thread. This is due to the small delay that may // [DummyTraffic.Pause] for more details)
// occur between calling [DummyTraffic.SetStatus] and the sending thread taking
// into effect that status change.
// //
// Returns: // Returns:
// - Returns true if sending thread is sending dummy messages and false if // - bool - Returns true ([dummy.Running]) if the sending thread is sending
// sending thread is paused/stopped and is not sending dummy messages // messages and false ([dummy.Paused]) if the sending thread is not sending
// (boolean). // messages.
func (dt *DummyTraffic) GetStatus(js.Value, []js.Value) any { func (dt *DummyTraffic) GetStatus(js.Value, []js.Value) any {
return dt.api.GetStatus() return dt.api.GetStatus()
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment