diff --git a/internal/internal_coroutines_test.go b/internal/internal_coroutines_test.go index eb3744aeb..4e3478961 100644 --- a/internal/internal_coroutines_test.go +++ b/internal/internal_coroutines_test.go @@ -420,6 +420,31 @@ func TestBufferedChannelGet(t *testing.T) { require.EqualValues(t, expected, history) } +func TestChannelName(t *testing.T) { + d := createNewDispatcher(func(ctx Context) { + const namedBufferedChannel = "named-buffered-channel" + ch1 := NewNamedBufferedChannel(ctx, namedBufferedChannel, 1) + assert.Equal(t, namedBufferedChannel, ch1.Name()) + + const namedChannel = "named-channel" + ch2 := NewNamedChannel(ctx, namedChannel) + assert.Equal(t, namedChannel, ch2.Name()) + + var receiveChannel ReceiveChannel = ch2 + assert.Equal(t, namedChannel, receiveChannel.Name()) + + var sendChannel SendChannel = ch2 + assert.Equal(t, namedChannel, sendChannel.Name()) + + const signalChannel = "signal-channel" + ch3 := GetSignalChannel(ctx, signalChannel) + assert.Equal(t, signalChannel, ch3.Name()) + }) + defer d.Close() + requireNoExecuteErr(t, d.ExecuteUntilAllBlocked(defaultDeadlockDetectionTimeout)) + require.True(t, d.IsDone()) +} + func TestNotBlockingSelect(t *testing.T) { var history []string d := createNewDispatcher(func(ctx Context) { diff --git a/internal/internal_workflow.go b/internal/internal_workflow.go index e70724da2..cc6eb852d 100644 --- a/internal/internal_workflow.go +++ b/internal/internal_workflow.go @@ -751,6 +751,10 @@ func getStateIfRunning(ctx Context) *coroutineState { return state } +func (c *channelImpl) Name() string { + return c.name +} + func (c *channelImpl) CanReceiveWithoutBlocking() bool { return c.recValue != nil || len(c.buffer) > 0 || len(c.blockedSends) > 0 || c.closed } diff --git a/internal/workflow.go b/internal/workflow.go index 5eb13d9ef..70783a36a 100644 --- a/internal/workflow.go +++ b/internal/workflow.go @@ -68,6 +68,13 @@ var ( type ( // SendChannel is a write only view of the Channel SendChannel interface { + // Name returns the name of the Channel. + // If the Channel was retrieved from a GetSignalChannel call, Name returns the signal name. + // + // A Channel created without an explicit name will use a generated name by the SDK and + // is not deterministic. + Name() string + // Send blocks until the data is sent. Send(ctx Context, v interface{}) @@ -80,6 +87,13 @@ type ( // ReceiveChannel is a read only view of the Channel ReceiveChannel interface { + // Name returns the name of the Channel. + // If the Channel was retrieved from a GetSignalChannel call, Name returns the signal name. + // + // A Channel created without an explicit name will use a generated name by the SDK and + // is not deterministic. + Name() string + // Receive blocks until it receives a value, and then assigns the received value to the provided pointer. // Returns false when Channel is closed. // Parameter valuePtr is a pointer to the expected data structure to be received. For example: