Git Product home page Git Product logo

async's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

async's Issues

Add Swift 2.0 Version Tag

Hi,

Would it be possible to tag a release for swift 2.0, so that we can add Async as a dependency in our pods?

Functions need public access qualifier

In Xcode 6.1.1 Swift public classes need public on each function that is externally accessed. Currently methods like Async.main both static and instance have default access qualifiers, which is now internal meaning only the module defining Async can use them.

Cartfile

when i use Cartfile
github "duemunk/Async" then has an error
Project "AsyncExample.xcodeproj" has no shared schemes

Code Coverage

Add Code Coverage to verify that tests cover all the bases.

Async.background reports/uses queues other than background

I made a new Swift project (single view controller) and added Async.swift file. I used the following sample code in my viewDidLoad:

Async.background {
    println("A: This is run on the \(qos_class_self().description) (expected \(QOS_CLASS_BACKGROUND.description))")
}.main {
    println("B: This is run on the \(qos_class_self().description) (expected \(qos_class_main().description)), after the previous block")
}

Running the project multiple times, the results I get are either:

A: This is run on the User Initiated (expected Background)
B: This is run on the Main (expected Main), after the previous block

Or:

A: This is run on the Main (expected Background)
B: This is run on the Main (expected Main), after the previous block

Never do I get the first block reporting that it is running on the background queue.

Xcode 6.1.1 (6A2008a)

git tag 1.2.0

It seems podspec is bumped, but git tag is not set yet.
Can you please add it?

Swift 2.0 support please

public extension qos_class_t {

/**
 Description of the `qos_class_t`. E.g. "Main", "User Interactive", etc. for the given Quality of Service class.
*/
var description: String {
    get {
        switch self {
        case qos_class_main(): return "Main"
        case QOS_CLASS_USER_INTERACTIVE: return "User Interactive"
        case QOS_CLASS_USER_INITIATED: return "User Initiated"
        case QOS_CLASS_DEFAULT: return "Default"
        case QOS_CLASS_UTILITY: return "Utility"
        case QOS_CLASS_BACKGROUND: return "Background"
        case QOS_CLASS_UNSPECIFIED: return "Unspecified"
        default: return "Unknown"
        }
    }
}

}

ERROR: binary operator '~=' cannot be applied to two 'qos_class_t' operands

Travis CI not running tests

I can't make Travis CI work (spoiler: I haven't used it before). Check it our here.

For every single test, the log states:

Test did not run: the test bundle stopped running or crashed before the test suite started.

The tests are only run for the OS X target.

dispatch_apply Cannot invoke

Hi guys,

I noticed this lib wasn't working anymore. I fixed it this way

public struct Apply {

    // DSL for GCD dispatch_apply()
    //
    // Apply runs a block multiple times, before returning. 
    // If you want run the block asynchounusly from the current thread, 
    // wrap it in an Async block, 
    // e.g. Async.main { Apply.background(3) { ... } }

    public static func userInteractive(iterations: UInt, block: UInt -> ()) {
        dispatch_apply(Int(iterations), GCD.userInteractiveQueue()) { (iteration) -> Void in
            block(UInt(iteration))
            return
        }
    }
    public static func userInitiated(iterations: UInt, block: UInt -> ()) {
        dispatch_apply(Int(iterations), GCD.userInitiatedQueue()) { (iteration) -> Void in
            block(UInt(iteration))
            return
        }
    }
    public static func utility(iterations: UInt, block: UInt -> ()) {
        dispatch_apply(Int(iterations), GCD.utilityQueue()) { (iteration) -> Void in
            block(UInt(iteration))
            return
        }
    }
    public static func background(iterations: UInt, block: UInt -> ()) {
        dispatch_apply(Int(iterations), GCD.backgroundQueue()) { (iteration) -> Void in
            block(UInt(iteration))
            return
        }
    }
    public static func customQueue(iterations: UInt, queue: dispatch_queue_t, block: UInt -> ()) {
        dispatch_apply(Int(iterations), queue) { (iteration) -> Void in
            block(UInt(iteration))
            return
        }
    }
}

Cannot load underlying module for 'Async'

installed the pod and when 'Import Async' in the main via controller got this error.
Cannot load underlying module for 'Async'

can build and run the 'AsyncExample iOS' w/o error

total noob here, any advice is appreciated

Test for cancel doesn't work (iOS tests)

Unless I add a sleep after the waitForExpectations(...) block2 doesn't get a chance to fire even if it isn't cancelled. Try removing the block2.cancel() and see if it still passes.

I've added this to my version to make it fail and then added the block2.cancel back to make it pass again:

NSThread.sleepForTimeInterval(1.0)

Generally I'm getting a lot of failures on your master when I run your tests. I don't know if it is because I'm on 10.9 so the simulator isn't handling everything properly or something like that. I don't think that this general issue is a problem with your tests.

BTW do you know what happens to blocks chained on a cancelled block? Are they cancelled too or do they run immediately on the cancel? I'm currently implementing cancel behaviour but wasn't sure how the main library (or GCD itself behaves). I'll have another look for the docs later.

Carthage Failure building tvOS

Not sure if this is an issue in Carthage, or the tvOS scheme needs to code sign the framework in the Async project.

*** Building scheme "Async tvOS" in Async.xcodeproj
** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)
CodeSign error: code signing is required for product type 'Framework' in SDK 'tvOS 9.0'
A shell task failed with exit code 65:
** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)

Carthage build fails

carthage_update produces the following error:
Failed to discover shared schemes in project AsyncPodsExample.xcodeproj—either the project does not have any shared schemes, or xcodebuild never returned

I am using Async 1.6.4 with the following Cartfile:
github "duemunk/Async" ~> 1.6

wait() on condition

Hello,

Thanks for the library, this is great!

I am using the library like this:

            var lock = NSObject()
            self.jobs = [Job]()
            Async.utility {
                for detailedResponse in responses {
                    Async.background {
                        var job = self.readJob(detailedResponse)
                        self.synced(lock) {
                            self.jobs!.append(job)
                        }
                        return
                    }
                }
                while self.jobs?.count != reponses.count {
                    println("Waiting")
                }
                return
            }.main {
                println("JOBS.COUNT: \(self.jobs?.count)")
                return
            }

where the synced function is found here: https://gist.github.com/Kaelten/7914a8128eca45f081b3

What I'm talking about is line with:

                while self.jobs?.count != responses.count {
                    println("Waiting")
                }

This ensures that all iterations of the loop complete before continuing to the next chain.

Maybe have a wait() function with timeout and a condition as well? So that you can pass it a function that returns a bool, and it will wait until either timeout is reached, or condition is true?

Just a thought, and I'm new to swift and GCD so please pardon any newbieness

This doesn't work at all via cocoa pods

The pod spec is saying source files are in the Sources directory but they aren't, they're in a Async.swift in the root.

This results in a pod being adding with no source files and no functionality.

qos_class_t error

Pods/Async/Source/Async.swift:280:24: Redundant conformance of 'qos_class_t' to protocol 'Equatable'

screen shot 2015-11-09 at 5 08 06 pm

Using Async with completion block

I found this bug when trying to use Async in my custom func with background operation and completion block as last parameter, but problem seems to exist in any situation of this kind:

    var request = NSMutableURLRequest(URL: kSomeURL)
    let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
        dispatch_async(dispatch_get_main_queue(), {
            println("this works (even if Async block below is deleted")
        })
        Async.main {
            println("this doesn't work when dispatch_async block above is deleted")
        }
    })

Any idea?

Let cancel() return if block successfully was cancelled

Unfortunately the dispatch_block_testcancel() doesn't behave as expected. It just return whether or not you called dispatch_block_cancel() on a block, not if the block was successfully cancelled before being dispatched to a queue.

If the behavior of dispatch_block_testcancel() changes, the solution would look as follows:

func cancel() -> Bool {
    dispatch_block_cancel(block) // Cancel block
    let success = dispatch_block_testcancel(block) // Test if block was successfully cancelled
    return success != 0
}

Module name conflict.

Hello.

I like Async a lot. I fork it and try to make it support Carthage. When I try to create build targets. Interesting things happened.

The module name 'Async' is causing a could not build Objective-C module 'Async' bug. When I try other names such as SwiftAsync. It works fine.

I'm wondering what is the best choice to support Carthage... What do you think?

Arguments and return values to blocks

Currently Async supports passing parameters through an external var like:

var date: NSDate?
Async.background {
    date = NSDate()
}.main {
    // Access date 
}

Possible syntax for a better solution:

Async.background {
    let date = NSDate()
}.main(date) {
    // Access date
}

I have no idea if or how this is possible – please let me know if you do!

Should I update my MAC OS?

My environment is OS 10.9.4 and Xcode 6 beta 5. I have tried to use Async in my iOS app, but it failed in the simulator (iOS 8).
I didn't modify anything, just run the two projects "AsyncExample iOS" and "AsyncExample iOSTests".

"AsyncExample iOS" printed these:
A: This is run on the Main (expected Background)
B: This is run on the Main (expected Main), after the previous block

"AsyncExample iOSTests" just succeed for the functions "testAsyncMain", "testAfterMain" and "testCancel". Other functions failed because qos_class_self() returned 0, which wasn't equal to any qos class.

Is MAC OS version the reason?

Swift 2.0

It seems to not work with Swift 2.0, I have corrected the errors however it crashes everytime I use Async.

Issue is here :

private func chain(block chainingBlock: dispatch_block_t, runInQueue queue: dispatch_queue_t) -> Async {
// See Async.async() for comments
let _chainingBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, chainingBlock)
dispatch_block_notify(self.block, queue, _chainingBlock)
return Async(_chainingBlock)
}

it crashes on the dispatch_block_notify

Merge master branch into feature/Swift_2.0 for Carthage build.

Current 23aaf8d (feature/Swift_2.0 branch) doesn't contain any xcodeproj or xcworkspace to build Async.framework, so carthage build will never get started.

It seems current master branch (v1.2.1) already has one, so please merge it into feature/Swift_2.0 so that I can test Swift 2 using Carthage.

CocoaPods Trunk

I was wondering if you intended to push this library to Cocoapod's trunk. There is currently an Async library that would conflict with this one so a name change might be needed. This would allow users to use pod 'AsyncSwift' in their Podfile

Guide to get setup on trunk

Thanks for the amazing work 👍

Async for non-GCD async operations

It can be very useful if Async can use with async operations.

Right now, I think Async can use only with sync operations.

Async.background {
  // do some "sync" stuff 1
}.background {
  // do some "sync" stuff 2 after sync stuff 1
}

But if I use some async operations such as Alamofire to upload files. Now the chain is just not wait for an upload to be finished.

Async.background {
  // async upload
  Alamofire.upload(.POST, "http://httpbin.org/post", file: fileURL)
    .reponseJSON { (_, _, JSON, _) in
        // upload done!!
    }
}.background {
  // do some stuff S after upload done!! ------>> Sorry S() is doing right away and not wait
  S()
}

An idea for accomplish this is something like passing a done block and waiting for done() to be called to continue to the next Async chain. I saw Quick/Nimble use this for waitUntil operation here.

So, here is a use case proposal.

Async.background { done in
  // async upload
  Alamofire.upload(.POST, "http://httpbin.org/post", file: fileURL)
    .reponseJSON { (_, _, JSON, _) in
        // upload done!!
        done()
    }
}.background {
  // do some "sync" stuff S1 after upload done!!
  S1()
}.background { done in
  // do some "async" stuff A1 after S1
  A1 { done() }
}.main {
  // All uploading, S1 and A1 are done, updates UI here
}

The Async is now very smart and every operations (.background, .main, .utility, etc..) can take a parameterless block for sync operations and a "one parameter block" (that parameter is another block expose as parameter name done) for async operations.

Any thought or possibility?

Binary operator '~=' cannot be applied to two 'qos_class_t' operands.

I just added this project via Cocoapods and it won't compile (haven't tried to use it yet, so I haven't written any code that uses it). It gives me the error in the title.

This happens here:

// MARK: - qos_class_t

public extension qos_class_t {

    // Convenience description of qos_class_t
    // Calculated property
    var description: String {
        get {
            switch self {
            case qos_class_main(): return "Main"
            case QOS_CLASS_USER_INTERACTIVE: return "User Interactive"
            case QOS_CLASS_USER_INITIATED: return "User Initiated"
            case QOS_CLASS_DEFAULT: return "Default"
            case QOS_CLASS_UTILITY: return "Utility"
            case QOS_CLASS_BACKGROUND: return "Background"
            case QOS_CLASS_UNSPECIFIED: return "Unspecified"
            default: return "Unknown"
            }
        }
    }
}

The error shows up in all cases.

I will see if I can fix this. I may just delete the description method in the extension (but don't worry, I won't be pushing that).

no such module Async

When I install it with a cocoapods, I need to use import AsyncSwift instead of import Async
set .module_name for podspec
spec.module_name = 'Async'

Why dont support dispatch_once?

Hi,

You said "I've found no need for dispatch_once in Swift" in #2 .
Could you please explain why no need to use dispatch_one in Swift?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.