Coder Social home page Coder Social logo

craft'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

Watchers

 avatar  avatar  avatar  avatar  avatar

craft's Issues

Seems to run on the main thread...

Hi,

I'm creating an iOS app with a table view and a spinner to load data over the network (which is mocked with a call to sleep, so far).
The problem is that the UI is blocked until the promise returns.
Here is my code :

    /**
     * Called when the spinner animates
     */
    func refresh(sender:AnyObject)
    {
        println("DataViewController.refresh() : begin")
            API.retrievePosts().then({(value: Value) -> Value in
                dispatch_async(dispatch_get_main_queue()) {
                    self.data += ["It", "Does", "Work"]
                    self.tableView.reloadData()
                    self.refreshControl.endRefreshing()
                }
                println("DataViewController.refresh() : data successfully refreshed")
                return nil
            }, reject: {(value: Value) -> Value in
                dispatch_async(dispatch_get_main_queue()) {
                    self.refreshControl.endRefreshing()
                    self.setMessage(NSLocalizedString("loading_posts_failed", comment: "text saying that posts could not be loaded"))
                }
                println("DataViewController.refresh() : Error while refreshing data : \(value)")
                return nil
            })
// if I wait 3 seconds with the method below instead, the UI does not block
//        var delayInSeconds = 3.0;
//        var popTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delayInSeconds * Double(NSEC_PER_SEC)));
//        dispatch_after(popTime, dispatch_get_main_queue()) { () -> Void in
//            // When done requesting/reloading/processing invoke endRefreshing, to close the control
//            self.refreshControl!.endRefreshing()
//        }
        println("refreshing")
        return
    }

And here is the mock method to retrieve posts :

    public static func retrievePosts() -> Promise {
        ++j
        return Craft.promise({(resolve: (value: Value) -> (), reject: (value: Value) -> ()) -> () in
            sleep(3)
            if self.j % 3 == 0 {// fails once every 3 attempt
                reject(value: "Network failure")
            } else {
                resolve(value: nil)
            }
        })
    }

So it seems that the promise runs on the UI thread. Or at least the sleep statement.

Xcode 6.1?

Hi, thanks for providing this library. Would you plan to update the library to support Xcode 6.1? It currently has the following compilation error.

        promise.then({
            (value: Value) -> Value in

            let res = SettledResult(state: PromiseState.FULFILLED, value: value)
            results[index] = res
            // *** cannot reference a local function within captures from another local function  ***
            return response(value)
        }, reject: {
            (value: Value) -> Value in

            let res = SettledResult(state: PromiseState.REJECTED, value: value)
            results[index] = res

            // *** cannot reference a local function within captures from another local function  ***
            return response(value)
        })

Thanks
Charles

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.