Skip to content

Instantly share code, notes, and snippets.

@renestein
renestein / GenericNullable1.cs
Last active Sep 2, 2021
GenericNullable1.cs
View GenericNullable1.cs
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
MyStack<MyItem> stack = new MyStack<MyItem>();
public class MyStack<T> where T : class
{
private T[] _items;
View OOP_actor.cpp
//Actor inherits from the ActorPolicy class.
class TestActor : public Actors::ActorPolicy
{
public:
TestActor() : ActorPolicy{}
{
}
View fasyncactor.cpp
TEST(SimpleActorTest, WhenUsingAsyncStatefulActorThenHasExpectedState)
{
const int MESSAGES_COUNT = 101;
const int EXPECTED_STATE = MESSAGES_COUNT;
auto seenMessages = 0;
auto testState = 0;
{
//Create the actor (asynchronous logic/with state/no reply).
auto stateFullActor = RStein::AsyncCpp::Actors::CreateAsyncSimpleActor<int, int>([&seenMessages, &testState](const int& message, const int& state)->Task<int>
{
View DataFlowForkJoin.cpp
Tasks::Task<size_t> WhenAsyncForkJoinDataflowThenAllInputsProcessedImpl(int inputItemsCount)
{
//Create TransformBlock. As the name of the block suggests, TransformBlock transforms input to output.
//Following block transforms int to string.
auto transform1 = DataFlowAsyncFactory::CreateTransformBlock<int, int>([](const int& item)-> Tasks::Task<int>
{
//Simulate work
co_await Tasks::GetCompletedTask();
auto message = "int: " + to_string(item) + "\n";
cout << message;
View backuprpi.sh
#!/bin/bash
ERROR_BACKUP_DIRECTORY_CREATE=80;
ERROR_BACKUP_ERROR=81;
BACKUP_PATH="/mount/OMEGA_1/Public/RPI_BACKUP"
BACKUP_DIR=$(date +"%Y-%m-%d-%HH-%MM")
FULL_BACKUP_FILE_PATH="$BACKUP_PATH$BACKUP_DIR"
oldDir=$(pwd)
View Dispose_When_Tasks_Are_Queued_Then_All_Tasks_Are_Executed.cs
[TestMethod]
public virtual async Task Dispose_When_Tasks_Are_Queued_Then_All_Tasks_Are_Executed()
{
const int NUMBER_OF_TASKS = 1000;
const int DELAY_TASK_CAN_CONTINUE_SIGNAL_S = 1;
int numberOfTasksExecuted = 0;
var waitForSignalCts = new CancellationTokenSource();
var tasks = Enumerable.Range(0, NUMBER_OF_TASKS)
View WithTaskFactory_When_One_Task_Is_Queued_Then_Task_is_Executed.cs
[TestMethod]
public async Task WithTaskFactory_When_One_Task_Is_Queued_Then_Task_is_Executed()
{
bool wasTaskExecuted = false;
await TestTaskFactory.StartNew(() => wasTaskExecuted = true);
Assert.IsTrue(wasTaskExecuted);
}
[TestMethod]
View Ctor_When_Number_Of_Threads_Is_Zero_Then_Throws_ArgumentOutOfRangeException.cs
[TestMethod]
[ExpectedException(typeof (ArgumentOutOfRangeException))]
public void Ctor_When_Number_Of_Threads_Is_Zero_Then_Throws_ArgumentOutOfRangeException()
{
var threadPool = new IoServiceThreadPoolScheduler(m_ioService, 0);
}
[TestMethod]
[ExpectedException(typeof (ArgumentOutOfRangeException))]
public void Ctor_When_Number_Of_Threads_Is_Negative_Then_Throws_ArgumentOutOfRangeException()
View Ctor_When_Io_Service_Is_Null_Then_Throws_ArgumentException.cs
[TestMethod]
[ExpectedException(typeof (ArgumentNullException))]
public void Ctor_When_Io_Service_Is_Null_Then_Throws_ArgumentException()
{
var threadPool = new IoServiceThreadPoolScheduler(null);
}
View IAutonomousSchedulerTests.cs
public abstract class IAutonomousSchedulerTests : ITaskSchedulerTests
{
private TaskFactory m_testTaskFactory;
protected abstract IProxyScheduler ProxyScheduler
{
get;
}
public TaskFactory TestTaskFactory