Task

1.0.0

Combine Tasks
0xLeif/Task

What's New

1.0.0

2021-05-20T02:14:32Z

Task

promise

promise<T>(
  work: @escaping (@escaping Future<T, Error>.Promise) -> Void
) -> Future<T, Error>

promise<T>(
  work: @escaping (@escaping Future<T?, Error>.Promise) -> Void
) -> Future<T?, Error>

promise(
  work: @escaping (@escaping Future<Void, Error>.Promise) -> Void
) -> Future<Void, Error>

do

do<T>(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> T
) -> Future<T, Error>
                               
do<T>(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> T?
) -> Future<T?, Error>

do(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> Void = {}
) -> Future<Void, Error>

main

main<T>(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> T
) -> Future<T, Error>

main<T>(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> T?
) -> Future<T?, Error>

main(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> Void = {}
) -> Future<Void, Error>

fetch

fetch(url: URLRequest) -> Future<(Data?, URLResponse?), Error>

fetch(url: URL) -> Future<(Data?, URLResponse?), Error>

post

post(request: URLRequest) -> Future<(Data?, URLResponse?), Error>

post(url: URL, withData data: (() -> Data)? = nil) -> Future<(Data?, URLResponse?), Error>

Task Examples

.sink(SinkEvent)

Task
    .do(withDelay: 5)
    .sink(.success { someFunction() })
    .store(in: &bag)

.sink(() -> [SinkEvent])

Task
    .do(withDelay: 5) {
        "Hello World!"
}
.sink {
    [
        .completion {
            sema.signal()
        },
        .success { value in
            XCTAssertEqual(value, "Hello World!")
        },
        .failure { _ in
            XCTAssert(false)
        }
    ]
}
.store(in: &bag)

Task

promise

promise<T>(
  work: @escaping (@escaping Future<T, Error>.Promise) -> Void
) -> Future<T, Error>

promise<T>(
  work: @escaping (@escaping Future<T?, Error>.Promise) -> Void
) -> Future<T?, Error>

promise(
  work: @escaping (@escaping Future<Void, Error>.Promise) -> Void
) -> Future<Void, Error>

do

do<T>(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> T
) -> Future<T, Error>
                               
do<T>(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> T?
) -> Future<T?, Error>

do(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> Void = {}
) -> Future<Void, Error>

main

main<T>(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> T
) -> Future<T, Error>

main<T>(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> T?
) -> Future<T?, Error>

main(
  withDelay delay: UInt32 = 0,
  work: @escaping () throws -> Void = {}
) -> Future<Void, Error>

fetch

fetch(url: URLRequest) -> Future<(Data?, URLResponse?), Error>

fetch(url: URL) -> Future<(Data?, URLResponse?), Error>

post

post(request: URLRequest) -> Future<(Data?, URLResponse?), Error>

post(url: URL, withData data: (() -> Data)? = nil) -> Future<(Data?, URLResponse?), Error>

Task Examples

.sink(SinkEvent)

Task
    .do(withDelay: 5)
    .sink(.success { someFunction() })
    .store(in: &bag)

.sink(() -> [SinkEvent])

Task
    .do(withDelay: 5) {
        "Hello World!"
}
.sink {
    [
        .completion {
            sema.signal()
        },
        .success { value in
            XCTAssertEqual(value, "Hello World!")
        },
        .failure { _ in
            XCTAssert(false)
        }
    ]
}
.store(in: &bag)

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 00:30:30 GMT-0900 (Hawaii-Aleutian Daylight Time)