-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set CallbackOnReceive back to one shot.
- Loading branch information
1 parent
d30cfcb
commit 53288c8
Showing
9 changed files
with
295 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using AsyncFiberWorks.Core; | ||
using System; | ||
|
||
namespace AsyncFiberWorks.Channels | ||
{ | ||
/// <summary> | ||
/// Extensions of actions and contexts. | ||
/// </summary> | ||
public static class ActionAndFiberExtensions | ||
{ | ||
/// <summary> | ||
/// Create an action to be executed on the specified context. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <param name="fiber">Target fiber.</param> | ||
/// <param name="action">Action.</param> | ||
/// <returns>Action with enqueue.</returns> | ||
public static Action<T> CreateAction<T>(this IExecutionContext fiber, Action<T> action) | ||
{ | ||
if (fiber == null) | ||
{ | ||
return action; | ||
} | ||
else | ||
{ | ||
return (msg) => fiber.Enqueue(() => action(msg)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace AsyncFiberWorks.Core | ||
{ | ||
/// <summary> | ||
/// One shot executor. It is executed only once the first time. | ||
/// </summary> | ||
public class OneShotExecutor : IExecutor | ||
{ | ||
private bool _fired = false; | ||
|
||
/// <summary> | ||
/// Execute only first one. | ||
/// </summary> | ||
/// <param name="toExecute"></param> | ||
public void Execute(List<Action> toExecute) | ||
{ | ||
if (_fired) return; | ||
foreach (var action in toExecute) | ||
{ | ||
_fired = true; | ||
Execute(action); | ||
break; | ||
} | ||
} | ||
|
||
///<summary> | ||
/// Executes a single action. | ||
///</summary> | ||
///<param name="toExecute"></param> | ||
public void Execute(Action toExecute) | ||
{ | ||
if (!_fired) | ||
{ | ||
_fired = true; | ||
toExecute(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.