<commit_before>﻿using System;
using System.Threading;
using System.Threading.Tasks;
using ActorInterface;
using TypedActorInterface;

namespace ActorHelpers
{
    public class ActorTaskCompletionSource<T>
    {
        private readonly IActorRuntime runtime;
        private readonly ITaskCompletionSource source;

        public Task<T> Task { get; }

        public ActorTaskCompletionSource(IActorRuntime r, ITypedActorRuntime typedRuntime)
        {
            runtime = r;

            Task = runtime.StartNew(() =>
            {
                TaskCompletionSourceHelper.Msg res =
                    (TaskCompletionSourceHelper.Msg)
                        runtime.CurrentMailbox().Receive();

                if(res.state == TaskStatus.Canceled)
                    throw new TaskCanceledException();

                return (T) res.result;
            });

            source =
                typedRuntime.Create<ITaskCompletionSource>(
                    new TaskCompletionSourceHelper(runtime.MailboxFromTask(Task)));
        }

        public void SetResult(T res)
        {
            var mailbox = runtime.CreateMailbox<object>();
            source.SetResult(res, mailbox);
            var ex = (Exception) mailbox.Receive();
            if (ex != null)
            {
                throw ex;
            }
        }

        public void SetCanceled()
        {
            var mailbox = runtime.CreateMailbox<object>();
            source.SetCanceled(mailbox);
            var ex = (Exception) mailbox.Receive();
            if (ex != null)
            {
                throw ex;
            }
        }


    }
}<commit_msg>Small fix to TaskCompletionSource.<commit_after>﻿using System;
using System.Threading;
using System.Threading.Tasks;
using ActorInterface;
using TypedActorInterface;

namespace ActorHelpers
{
    public class ActorTaskCompletionSource<T>
    {
        private readonly IActorRuntime runtime;
        private readonly ITaskCompletionSource source;

        public Task<T> Task { get; }

        public ActorTaskCompletionSource(IActorRuntime r, ITypedActorRuntime typedRuntime)
        {
            runtime = r;

            Task = runtime.StartNew(() =>
            {
                TaskCompletionSourceHelper.Msg res =
                    (TaskCompletionSourceHelper.Msg)
                        runtime.CurrentMailbox().Receive();

                runtime.CancelSelf();

                return (T) res.result;
            });

            source =
                typedRuntime.Create<ITaskCompletionSource>(
                    new TaskCompletionSourceHelper(runtime.MailboxFromTask(Task)));
        }

        public void SetResult(T res)
        {
            var mailbox = runtime.CreateMailbox<object>();
            source.SetResult(res, mailbox);
            var ex = (Exception) mailbox.Receive();
            if (ex != null)
            {
                throw ex;
            }
        }

        public void SetCanceled()
        {
            var mailbox = runtime.CreateMailbox<object>();
            source.SetCanceled(mailbox);
            var ex = (Exception) mailbox.Receive();
            if (ex != null)
            {
                throw ex;
            }
        }


    }
}
{'fraction_non_alphanumeric': 0.08438558669541114, 'fraction_numerical': 0.0, 'mean_word_length': 1.5921787709497206, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6189250', 'n_tokens_mistral': 813, 'n_tokens_neox': 772, 'n_words': 171}