public UniTask Run()
            {
                var t = UniTask.Run(async() =>
                {
                    try
                    {
                        while (true)
                        {
                            //
                            // NOTE: Change this to readwrite and then it does work ???
                            // No more IOERROR
                            //

                            var flags = SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.ReadOnly;
#if __IOS__
                            flags = SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.ReadWrite;
#endif
                            using (var dbConnection = new DbConnection(flags))
                            {
                                var records = dbConnection.Table <TestObj>().ToList();
                                System.Diagnostics.Debug.WriteLine($"{Environment.CurrentManagedThreadId} Read records: {records.Count}");
                            }

                            // sqlite-net : (No await so we stay on the same thread) but UniTask use same thread
                            await UniTask.Delay(10, cancellationToken: cancellationToken);
                            cancellationToken.ThrowIfCancellationRequested();
                        }
                    }
                    catch (OperationCanceledException)
                    {
                    }
                });

                return(t);
            }
        public IEnumerator TestInsertCommandCreation() => UniTask.ToCoroutine(async() =>
        {
            using (var dbConnection =
                       new DbConnection(SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create))
            {
                var obj1  = new TestObj();
                var obj2  = new TestObj();
                var taskA = UniTask.Run(() => { dbConnection.Insert(obj1); });
                var taskB = UniTask.Run(() => { dbConnection.Insert(obj2); });

                await UniTask.WhenAll(taskA, taskB);
            }
        });
示例#3
0
        public async Task Sample02()
        {
            using (var cubes = new SampleCubes(new Vector3(0f, 3f, 0f), new Vector3(0f, 3f, 0f), new Vector3(0f, 3f, 0f)))
            {
                await Anime.Delay(1f);

                await Task.WhenAll(
                    CircleAnimation(cubes[0], 0.0f),
                    CircleAnimation(cubes[1], 0.2f),
                    CircleAnimation(cubes[2], 0.4f)
                    );

                await Anime.Delay(1f);
            }
        }
        public IEnumerator TestLoad() => UniTask.ToCoroutine(async() =>
        {
            try
            {
                var tokenSource = new CancellationTokenSource();
                var tasks       = new List <UniTask>();
                tasks.Add(new DbReader(tokenSource.Token).Run());
                tasks.Add(new DbWriter(tokenSource.Token).Run());

                // Wait 5sec
                tokenSource.CancelAfter(5000);

                await UniTask.WhenAll(tasks);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        });
            public UniTask Run()
            {
                var t = UniTask.Run(async() =>
                {
                    try
                    {
                        while (true)
                        {
                            using (var dbConnection = new DbConnection(SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.ReadWrite))
                            {
                                System.Diagnostics.Debug.WriteLine($"{Environment.CurrentManagedThreadId} Start insert");

                                for (var i = 0; i < 50; i++)
                                {
                                    var newRecord = new TestObj()
                                    {
                                    };

                                    dbConnection.Insert(newRecord);
                                }

                                System.Diagnostics.Debug.WriteLine($"{Environment.CurrentManagedThreadId} Inserted records");
                            }

                            // sqlite-net : (No await so we stay on the same thread) but UniTask use same thread
                            await UniTask.Delay(1, cancellationToken: cancellationToken);
                            cancellationToken.ThrowIfCancellationRequested();
                        }
                    }
                    catch (OperationCanceledException)
                    {
                    }
                });

                return(t);
            }