This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
15 changed files
with
203 additions
and
141 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
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,3 @@ | ||
import PackageDescription | ||
|
||
let package = Package(name: "AlecrimAsyncKit") |
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
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
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
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
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
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,68 @@ | ||
// | ||
// Mapping.swift | ||
// AlecrimAsyncKit | ||
// | ||
// Created by Vanderlei Martinelli on 06/05/18. | ||
// Copyright © 2018 Alecrim. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - | ||
|
||
extension Task { | ||
|
||
public func map<U>(on queue: OperationQueue? = nil, closure: @escaping (Value) throws -> U) -> Task<U> { | ||
return async(on: queue) { | ||
let value = try self.await() | ||
let mappedValue = try closure(value) | ||
|
||
return mappedValue | ||
} | ||
} | ||
|
||
public func map<U>(on queue: OperationQueue? = nil, closure: @escaping (Value) -> U) -> Task<U> { | ||
return async(on: queue) { | ||
let value = try self.await() | ||
let mappedValue = closure(value) | ||
|
||
return mappedValue | ||
} | ||
} | ||
|
||
} | ||
|
||
extension Task { | ||
|
||
public func asNonFailable(on queue: OperationQueue? = nil) -> NonFailableTask<Value> { | ||
return async(on: queue) { | ||
return try! self.await() | ||
} | ||
} | ||
|
||
} | ||
|
||
// MARK: - | ||
|
||
extension NonFailableTask { | ||
|
||
public func map<U>(on queue: OperationQueue? = nil, closure: @escaping (Value) -> U) -> NonFailableTask<U> { | ||
return async(on: queue) { | ||
let value = try! self.await() | ||
let mappedValue = closure(value) | ||
|
||
return mappedValue | ||
} | ||
} | ||
|
||
} | ||
|
||
extension NonFailableTask { | ||
|
||
public func asFailable(on queue: OperationQueue? = nil) -> Task<Value> { | ||
return async(on: queue) { | ||
return try self.await() | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.