Skip to content

Commit

Permalink
Update URLSession example
Browse files Browse the repository at this point in the history
  • Loading branch information
koolhazcker authored and kzaher committed Feb 26, 2017
1 parent cfe403b commit 4e96e8a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Documentation/Why.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ So what are some practical examples?

### Easy integration

What if you need to create your own observable? It's pretty easy. This code is taken from RxCocoa and that's all you need to wrap HTTP requests with `NSURLSession`
What if you need to create your own observable? It's pretty easy. This code is taken from RxCocoa and that's all you need to wrap HTTP requests with `URLSession`

```swift
extension NSURLSession {
public func response(_ request: URLRequest) -> Observable<(Data, HTTPURLResponse)> {
extension URLSession {
public func response(request: URLRequest) -> Observable<(Data, HTTPURLResponse)> {
return Observable.create { observer in
let task = self.base.dataTask(with: request) { (data, response, error) in

Expand All @@ -261,8 +261,7 @@ extension NSURLSession {
observer.on(.completed)
}

let t = task
t.resume()
task.resume()

return Disposables.create(with: task.cancel)
}
Expand Down

0 comments on commit 4e96e8a

Please sign in to comment.