ChiaoteNi / StructuredCuoncurrencyDemo

This is a demo project to practice Swift Structured Concurrency

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StructuredCuoncurrencyDemo

This is a demo project to practice Swift Structured Concurrency with multiple parts.

Part I: (Jan. 31)

  • BasicDemo: This demo will show some basic things like:
    • The basic async await usage and how the executing thread will be. (although you shouldn't think of thread while using Structured Concurrency)
    • async let
    • The generic types of Task
    • yield
  • CancelDemo: This demo will show the following things:
    • The isCancelled changes status when the parent task is canceled
    • The isCancelled changes status when other Task throws an error
  • GroupingTasksDemo:
    • Just like the naming, this demo will show how to do grouping jobs.
  • MainActorDemo:
    • The order of execution
    • @MainActor attribute for function and closure

Part II: (Feb. 28)

  • AsyncSequence
    • AsyncMap for Sequence
    • AsyncSequence & AsyncIteratorProtocol protocol
    • AsyncStream & AsyncThrowingStream - onTermination triggered when canceling
    • The implementations of AsyncMapSequence & AsyncThrowingCompactMapSequence.
    • Implement a simple image downloader with the AsyncSequence

Part III: (May 9)

  • Actor
    • ActorDemo.playground: - MainActor - GlobalActor - Basic behaviors
    • CustomActorExecutorDemo.playground:
    • ActorReentrancyDemo.playground

Part IV: (Dec. 18)

  • TaskLocal
    • Basic behaviors of TaskLocal
    • Some potential usages of TaskLocal
  • AsyncResourceLimiter
    • A simple implementation to limit async function execution at the same time.
  • Some updates from Swift 5.9 for the Part II and III demonstrations

How to use this demo project?

Part I: All demos work with their demo view, which is compatible with SwiftUI Preview. Please use the demo project in the following way:

  • Place the demo view on the left side with the canvas, and the demo itself on the right.
  • For example: BasicDemoView (left) / BasicDemo (right). Screen Shot 2023-02-05 at 2 34 54 PM

Part II: Most of the demos are triggered by the test cases, so please use the demo project in the following way:

  • Place the demonstrations on the left side, and the test cases on the right.
  • For example: AsyncSequenceDemo.swift (left) / AsyncSequenceDemoTest.swift (right)." Screen Shot 2023-03-29 at 10 59 50 AM

Part III: All demonstrations can be found in the following playground files:

  • ActorDemo.playground
  • CustomActorExecutorDemo.playground
  • ActorReentrancyDemo.playground

Part IV: All demonstrations can be found in the following playground files:

  • TaskLocalDemo.playground
  • TaskLocalPlayground.playground
  • ExecutingLimiter.playground

Simply highlight sections of the code and interact directly within the playground.

About

This is a demo project to practice Swift Structured Concurrency


Languages

Language:Swift 100.0%