Skip to content

Commit

Permalink
Cleanup Code
Browse files Browse the repository at this point in the history
  • Loading branch information
veblush committed Jul 11, 2016
1 parent d237a11 commit 85f25c8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/TalkServer/BotActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,32 @@ private async Task LoginUser(string userId)
[MessageHandler]
private Task Handle(TimerMessage m)
{
return (_pattern != null) ? _pattern.OnTimer() : Task.FromResult(true);
return (_pattern != null) ? _pattern.OnTimer() : Task.CompletedTask;
}

Task IUserEventObserverAsync.Invite(string invitorUserId, string roomName)
{
return (_pattern != null) ? _pattern.OnInvite(invitorUserId, roomName) : Task.FromResult(true);
return (_pattern != null) ? _pattern.OnInvite(invitorUserId, roomName) : Task.CompletedTask;
}

Task IUserEventObserverAsync.Whisper(ChatItem chatItem)
{
return (_pattern != null) ? _pattern.OnWhisper(chatItem) : Task.FromResult(true);
return (_pattern != null) ? _pattern.OnWhisper(chatItem) : Task.CompletedTask;
}

Task IRoomObserverAsync.Enter(string userId)
{
return (_pattern != null) ? _pattern.OnEnter(userId) : Task.FromResult(true);
return (_pattern != null) ? _pattern.OnEnter(userId) : Task.CompletedTask;
}

Task IRoomObserverAsync.Exit(string userId)
{
return (_pattern != null) ? _pattern.OnExit(userId) : Task.FromResult(true);
return (_pattern != null) ? _pattern.OnExit(userId) : Task.CompletedTask;
}

Task IRoomObserverAsync.Say(ChatItem chatItem)
{
return (_pattern != null && chatItem.UserId != _patternContext.UserId) ? _pattern.OnSay(chatItem) : Task.FromResult(true);
return (_pattern != null && chatItem.UserId != _patternContext.UserId) ? _pattern.OnSay(chatItem) : Task.CompletedTask;
}

async Task IBotService.SayAsync(string message)
Expand Down
18 changes: 9 additions & 9 deletions src/TalkServer/BotPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,37 @@ protected BotPattern(Context context)

public virtual Task OnStart()
{
return Task.FromResult(true);
return Task.CompletedTask;
}

public virtual Task OnTimer()
{
return Task.FromResult(true);
return Task.CompletedTask;
}

public virtual Task OnInvite(string invitorUserId, string roomName)
{
return Task.FromResult(true);
return Task.CompletedTask;
}

public virtual Task OnWhisper(ChatItem chatItem)
{
return Task.FromResult(true);
return Task.CompletedTask;
}

public virtual Task OnEnter(string userId)
{
return Task.FromResult(true);
return Task.CompletedTask;
}

public virtual Task OnExit(string userId)
{
return Task.FromResult(true);
return Task.CompletedTask;
}

public virtual Task OnSay(ChatItem chatItem)
{
return Task.FromResult(true);
return Task.CompletedTask;
}

protected Task SayAsync(string message)
Expand Down Expand Up @@ -136,7 +136,7 @@ public override Task OnWhisper(ChatItem chatItem)
if (chatItem.Message.ToLower() == "kill")
_context.Service.Kill();

return Task.FromResult(0);
return Task.CompletedTask;
}

public override async Task OnSay(ChatItem chatItem)
Expand Down Expand Up @@ -202,7 +202,7 @@ public override Task OnWhisper(ChatItem chatItem)
if (chatItem.Message.ToLower() == "kill")
_context.Service.Kill();

return Task.FromResult(0);
return Task.CompletedTask;
}

public override Task OnStart()
Expand Down
11 changes: 4 additions & 7 deletions src/TalkServer/ClusterRoleWorkers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override Task Start()
_userTable = _context.System.ActorOf(
Props.Create(() => new DistributedActorTable<string>("User", _context.ClusterActorDiscovery, null, null)),
"UserTable");
return Task.FromResult(true);
return Task.CompletedTask;
}

public override async Task Stop()
Expand Down Expand Up @@ -175,8 +175,6 @@ public override async Task Start()

public override async Task Stop()
{
// stop gateway

await _gateway.CastToIActorRef().GracefulStop(
TimeSpan.FromSeconds(10),
InterfacedMessageBuilder.Request<IGateway>(x => x.Stop()));
Expand All @@ -199,7 +197,7 @@ public override Task Start()
_roomTable = _context.System.ActorOf(
Props.Create(() => new DistributedActorTable<string>("Room", _context.ClusterActorDiscovery, null, null)),
"RoomTable");
return Task.FromResult(true);
return Task.CompletedTask;
}

public override async Task Stop()
Expand Down Expand Up @@ -250,7 +248,6 @@ public override async Task Start()
ConnectEndPoint = _connectEndPoint,
GatewayLogger = LogManager.GetLogger(name),
TokenRequired = true,
TokenTimeout = TimeSpan.FromMinutes(1),
CreateChannelLogger = (ep, _) => LogManager.GetLogger($"Channel({ep})"),
ConnectionSettings = new TcpConnectionSettings { PacketSerializer = serializer },
PacketSerializer = serializer,
Expand Down Expand Up @@ -309,7 +306,7 @@ public override Task Start()
Props.Create(() => new DistributedActorTable<long>("Bot", _context.ClusterActorDiscovery, typeof(IncrementalIntegerIdGenerator), null)),
"BotTable");

return Task.FromResult(true);
return Task.CompletedTask;
}

public override async Task Stop()
Expand Down Expand Up @@ -338,7 +335,7 @@ public override Task Start()
"Bot", _context.ClusterActorDiscovery, typeof(BotActorFactory), new object[] { _context }, InterfacedPoisonPill.Instance)),
"BotTableContainer");

return Task.FromResult(true);
return Task.CompletedTask;
}

public override async Task Stop()
Expand Down
6 changes: 3 additions & 3 deletions src/TalkServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ private static int Main(string[] args)
string runner = null;
x.AddCommandLineDefinition("runner", val => runner = val);
x.SetServiceName("TalkServer");
x.SetDisplayName("TalkServer for Chatty");
x.SetDescription("TalkServer for Chatty using Akka.NET and Akka.Interfaced.");
x.SetServiceName("Chatty");
x.SetDisplayName("Chatty Service");
x.SetDescription("Chatty Service using Akka.NET and Akka.Interfaced. (https://github.com/SaladLab/Chatty)");
x.UseAssemblyInfoForServiceInfo();
x.RunAsLocalSystem();
Expand Down
6 changes: 3 additions & 3 deletions src/TalkServer/UserActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,19 @@ Task IUser.CreateBot(string roomName, string botType)
if (_clusterContext.BotTable != null)
_clusterContext.BotTable.Create(new object[] { roomName, type });

return Task.FromResult(0);
return Task.CompletedTask;
}

Task IUserMessasing.Whisper(ChatItem chatItem)
{
_eventObserver.Whisper(chatItem);
return Task.FromResult(0);
return Task.CompletedTask;
}

Task IUserMessasing.Invite(string invitorUserId, string roomName)
{
_eventObserver.Invite(invitorUserId, roomName);
return Task.FromResult(0);
return Task.CompletedTask;
}
}
}

0 comments on commit 85f25c8

Please sign in to comment.