public void Intercept(IInvocation invocation) { var method = invocation.Method; var td = method.ReturnType.GetTaskType(); switch (td.MethodType) { case TaskType.None: throw new NotSupportedException("Actor method should only return Task or Task<T>"); case TaskType.Task: invocation.ReturnValue = _Queue.Enqueue(() => { return(invocation.Call <Task>()); }); break; case TaskType.GenericTask: var mi = _Proceed.MakeGenericMethod(td.Type); mi.Invoke(this, new[] { invocation }); break; } }
public Task <T> Enqueue <T>(Func <Task <T> > function) { var task = _origin.Enqueue(function); _lastTask = task; return(task); }
private IEnumerator LoadAsyncCachedBinary(DownloadLicense license) { byte[] binary = new byte[] { }; Exception exception = null; _taskQueue.Enqueue(() => { try { binary = _modelLoadModule.Load(license); } catch (Exception ex) { exception = ex; } }); yield return(WaitFor()); if (OnProgress != null) { OnProgress(1.0f); } if (exception == null) { LoadVRMFromBinary(binary); } else if (OnError != null) { OnError(exception); } }
private void FileRegistrationTrackerOnProjectListChanged(object sender, ProjectsEventArgs e) { Logger.LogInfo("List of projects has changed: Enqueuing a partial file system scan"); // If we are queuing a task that requires rescanning the entire file system, // cancel existing tasks (should be only one really) to avoid wasting time _longRunningFileSystemTaskQueue.CancelCurrentTask(); _longRunningFileSystemTaskQueue.Enqueue(ProjectListChangedTaskId, cancellationToken => { // Pass empty changes, as we don't know of any file system changes for // existing entries. For new entries, they don't exist in the snapshot, // so they will be read form disk var emptyChanges = new FullPathChanges(ArrayUtilities.EmptyList <PathChangeEntry> .Instance); RescanFileSystem(e.Projects, emptyChanges, cancellationToken); }); }
public static Task Enqueue(this ITaskQueue queue, Action action) { return(queue.Enqueue(() => { action(); return Task.FromResult <object>(null); })); }
void EnqueueEvent <TEventArgs>(EventHandler <TEventArgs> handler, TEventArgs args) where TEventArgs : EventArgs { if (handler != null) { EventsQueue.Enqueue(() => handler(this, args)); } }
public static Task Enqueue(this ITaskQueue queue, Func <Task> action) { return(queue.Enqueue <object>(async() => { await action(); return null; })); }
public Task RepeatState() { _taskQueue.Enqueue(() => { CallbackStateChanged(_state); }); return(Task.CompletedTask); }
private void DirectoryChangeWatcherOnPathsChanged(IList <PathChangeEntry> changes) { _taskExecutor.ExecuteAsync(token => { if (!_isPaused) { _pathsChangedQueue.Enqueue(changes); _flushPathChangesTaskQueue.Enqueue(FlushPathsChangedQueueTaskId, FlushPathsChangedQueueTask); } }); }
public void ProcessRequestAsync(IpcRequest request) { if (request.RunOnSequentialQueue) { // Run on queue, with a unique ID since each request is unique _sequentialTaskQueue.Enqueue(new TaskId(String.Format("RequestId={0}", request.RequestId)), t => ProcessRequestWorker(request)); } else { _customThreadPool.RunAsync(() => ProcessRequestWorker(request)); } }
void EnqueueServiceResolution <TService>(System.Action <TService> setter, bool blocking) where TService : class, IService { if (blocking) { _taskQueue.Enqueue(() => { TService service = _serviceResolver.Get <TService>(); setter(service); }); return; } bool found = false; TService foundService = null; _taskQueue.Enqueue(() => { _serviceResolver.Get <TService>((result, service) => { foundService = service; setter(service); found = true; }); }); _taskQueue.Parallelize(() => found, -1, string.Format("find service {0}", typeof(TService).Name)).Done += result => { CoreLogger.LogDebug(LoggerModules.GameApplication, string.Format("done preparing service {0}: {1}; provider is: {2}", typeof(TService).Name, result, foundService == null ? "null" : foundService.GetType().Name)); }; }
public void Send(ReportBody body) { var content = GetJsonContent(body); _taskQueue.Enqueue(() => { try { _httpClient.PostAsync(_uri, content); } catch (HttpRequestException) { //ignore } }); }
private async Task <VpnEndpoint> EnqueueAsync(Func <Task <VpnEndpoint> > func, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(VpnEndpoint.Empty); } return(await _taskQueue.Enqueue(async() => { if (cancellationToken.IsCancellationRequested) { return VpnEndpoint.Empty; } return await func(); })); }
private void Queued(Action <CancellationToken> action, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return; } _taskQueue.Enqueue(() => { if (cancellationToken.IsCancellationRequested) { return; } action(cancellationToken); }); }
/// <summary> Fill queue with tasks </summary> /// <param name="pathParams"> Paths for input and output files </param> /// <param name="operation"> Process operation type </param> public void CreateTasks(FilePaths pathParams, IOperation operation) { Guard.NotNull(pathParams, $"{nameof(pathParams)}"); Guard.NotNull(operation, $"{nameof(operation)}"); var fileChunks = operation.SplitFile(pathParams.InputFilePath) .OrderBy(x => x.StartPosition); // Each task has it's number for operations which could required sequential processing var taskNumber = 0; foreach (var chunk in fileChunks) { var syncParams = _taskSyncParamsFactory.Create(taskNumber, ResetEvent, CanProceed); var task = _gzipTaskFactory.Create(pathParams, syncParams, chunk, operation); _taskQueue.Enqueue(task); taskNumber++; } }
/// <summary> /// Changes the current language. /// </summary> /// <param name="language">The language.</param> public void ChangeCurrentLanguage(LanguageInfo language) { language.Culture.DateTimeFormat = _systemFormat; var localizationChangingArgs = new LocalizationChangingEventArgs(language); _localizationChangingEvent.Publish(localizationChangingArgs); if (localizationChangingArgs.WaitingFor.IsEmpty()) { SetCurrentLanguage(language); } else { var waitTask = new WaitTask(Logger) { Handlers = localizationChangingArgs.WaitingFor.ToArray(), OnResult = result => { SetCurrentLanguage(language); } }; _taskQueue.Enqueue(waitTask); } }
public void RegisterFileAsync(FullPath path) { Logger.LogInfo("Register path \"{0}\"", path); _pendingFileRegistrations.Enqueue(FileRegistrationKind.Register, path); _taskQueue.Enqueue(FlushFileRegistrationQueueTaskId, FlushFileRegistrationQueueTask); }
public void Enqueue(TaskId id, Action <CancellationToken> task) { _taskQueue.Enqueue(id, task); }
public IEnumerator Init(bool block) { if (s_initInProgress) { CoreLogger.LogError(LoggerModules.GameApplication, "attempt to initialize kernel while already doing so!"); yield break; } Application.targetFrameRate = this.targetFrameRate; s_instance = this; s_initInProgress = true; _taskQueue = gameObject.AddMissingComponent <TaskQueue>(); _taskQueue.Active = false; EnqueueCreateResolvers(); EnqueueAddProviders(); EnqueuePreStageServiceResolution(block); _taskQueue.Enqueue(() => { LoadLoggerConfig(); }); EnqueueInitModules(int.MinValue, -1, block); EnqueueServiceResolution(block); EnqueueInitModules(0, 0, block); EnqueuePostStageServiceResolution(block); EnqueueInitModules(1, int.MaxValue, block); _taskQueue.Enqueue(() => { LoadLoggerConfig(); }); //register to the event that tells us when the queue is empty, //which implies we have finished initializing bool initDone = false; //when the task queue empties, we will know we are done _taskQueue.Enqueue(() => { //at this point we can set the static instance safely s_earlyAccess = false; //init is done s_initInProgress = false; initDone = true; }); //now start the actual initialization, by activating the queue float initStart = Time.time; //start running the init tasks _taskQueue.Active = true; if (block) { //the synchronous version: _taskQueue.HandleAll(); //at this point in time, the singleton is ready for use _gameModules.Start(); yield break; } else { //the async. version: //while(Time.time - initStart < initTimeout) while (true) { if (Time.time - initStart > initTimeout) { CoreLogger.LogWarning(LoggerModules.GameApplication, "timeout in creating GameApplication object"); } if (initDone) { //at this point in time, the singleton is ready for use _gameModules.Start(); yield return(StartCoroutine(WaitForStrangeServiceProviderInit())); InitDone(); CoreLogger.LogDebug(LoggerModules.GameApplication, "GameApplication succesfully finished Init!"); yield break; } yield return(null); } } }
private void FileSystemProcessorOnFilesChanged(object sender, FilesChangedEventArgs filesChangedEventArgs) { _taskQueue.Enqueue(UpdateFileContentsTaskId, cancellationToken => { UpdateFileContents(filesChangedEventArgs.ChangedFiles); }); }
private Task Queued(Func <Task> function) { return(_taskQueue.Enqueue(function)); }
public static void ExecuteAsync(this ITaskQueue queue, Action <CancellationToken> task) { queue.Enqueue(new TaskId("Unique"), task); }
private void Queued(Action action) { _taskQueue.Enqueue(action); }
private void FileSystemProcessorOnFilesChanged(object sender, FilesChangedEventArgs filesChangedEventArgs) { _taskQueue.Enqueue( new TaskId("FileSystemProcessorOnFilesChanged"), () => UpdateFileContents(filesChangedEventArgs.ChangedFiles)); }
public void NotifyEventCreation(EventSlim evt) { _taskQueue.Enqueue(new { RegistrationIds = evt.UserList.Where(user => !_isRequester(user.UserId, evt.InitiatorId.ToString()) && _isValidGCMId(user.GCMClientId)).Select(user => user.GCMClientId), NotificationData = PushMessageComposer.GetMessage(evt, "EventInvite") }); }
public void Refresh() { _taskQueue.Enqueue(RefreshTaskId, RefreshTask); }
public void AddFile(string filename) { _taskQueue.Enqueue(string.Format("AddFile(\"{0}\")", filename), () => AddFileTask(filename)); }
public static Task <T> Enqueue <T>(this ITaskQueue queue, Func <T> function) { return(queue.Enqueue(() => Task.FromResult(function()))); }
private void Origin_StateChanged(object sender, EventArgs <VpnState> e) { _taskQueue.Enqueue(() => OnStateChanged(e.Data)); }
private void DirectoryChangeWatcherOnPathsChanged(IList <PathChangeEntry> changes) { Logger.LogInfo("File change events: enqueuing an incremental file system rescan"); _pathsChangedQueue.Enqueue(changes); _flushPathChangesTaskQueue.Enqueue(FlushPathsChangedQueueTaskId, FlushPathsChangedQueueTask); }