-
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.
- Loading branch information
Leonard Sperry
committed
Dec 18, 2020
1 parent
854de29
commit 1b19683
Showing
3 changed files
with
141 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlClient; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Samples.AwaitMeansNoWait | ||
{ | ||
class MultiDataCallsSync | ||
{ | ||
IBookProvider _bookProvider; | ||
|
||
object GetPageInfo(int bookId) | ||
{ | ||
var book = _bookProvider.GetById(bookId); | ||
var booksByAuthor = _bookProvider.GetByAuthor(book.AuthorId); | ||
var booksInCategory = _bookProvider.GetTop10BooksInCategory(book.PrimaryCategoryId); | ||
|
||
return new { | ||
booksByAuthor, | ||
booksInCategory | ||
}; | ||
} | ||
object GetPageInfo2(int bookId) | ||
{ | ||
var book = _bookProvider.GetById(bookId); | ||
IEnumerable<Book> booksByAuthor = null; | ||
IEnumerable<Book> booksInCategory = null; | ||
Thread authorThread = new Thread(() => | ||
booksByAuthor = _bookProvider.GetByAuthor(book.AuthorId) | ||
); | ||
authorThread.Start(); | ||
Thread catThread = new Thread(() => | ||
booksInCategory = | ||
_bookProvider.GetTop10BooksInCategory(book.PrimaryCategoryId) | ||
); | ||
catThread.Start(); | ||
authorThread.Join(); | ||
catThread.Join(); | ||
|
||
return new | ||
{ | ||
booksByAuthor, | ||
booksInCategory | ||
}; | ||
} | ||
|
||
async Task<object> GetPageInfoAsync(int bookId) | ||
{ | ||
var book = await _bookProvider.GetByIdAsync(bookId); | ||
var booksByAuthor = _bookProvider.GetByAuthorAsync(book.AuthorId); | ||
var booksInCategory = _bookProvider | ||
.GetTop10BooksInCategoryAsync(book.PrimaryCategoryId); | ||
|
||
return new { | ||
booksByAuthor = await booksByAuthor, | ||
booksInCategory = await booksInCategory | ||
}; | ||
} | ||
} | ||
|
||
class Book | ||
{ | ||
public int AuthorId { get; set; } | ||
public int PrimaryCategoryId { get; set; } | ||
} | ||
|
||
class Catagory { } | ||
|
||
interface IBookProvider | ||
{ | ||
Book GetById(int bookId); | ||
Task<Book> GetByIdAsync(int bookId); | ||
|
||
IEnumerable<Book> GetTop10BooksInCategory(int categoryId); | ||
Task<IEnumerable<Book>> GetTop10BooksInCategoryAsync(int categoryId); | ||
|
||
IEnumerable<Book> GetByAuthor(int authorId); | ||
Task<IEnumerable<Book>> GetByAuthorAsync(int authorId); | ||
} | ||
} |
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,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Samples.AwaitMeansNoWait | ||
{ | ||
class NoAwait | ||
{ | ||
async Task<bool> DoWork() | ||
{ | ||
return await Task.Run(() => true); | ||
} | ||
|
||
Task<bool> DoWorkFixed() | ||
{ | ||
return Task.Run(() => true); | ||
} | ||
} | ||
} |
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,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Samples.brvtybd | ||
{ | ||
class ExpandingIdeas | ||
{ | ||
void Example(string input) | ||
{ | ||
while(!int.TryParse(input, out int choice) || choice < 1) | ||
{ | ||
Console.WriteLine("choose a valid option"); | ||
input = Console.ReadLine(); | ||
} | ||
} | ||
|
||
void Example2() | ||
{ | ||
var userGroupValidatorFactory = default(object); | ||
|
||
} | ||
|
||
object AddCategory(bool condition1, bool condition2) | ||
{ | ||
object dependency = null; | ||
object returnValue; | ||
|
||
return condition1 ? condition2 ? DoTheThing(dependency) : | ||
DoTheThing(default) : default; | ||
} | ||
|
||
object DoTheThing(object input) | ||
{ | ||
return default; | ||
} | ||
|
||
} | ||
} |