Skip to content

Add .delayUntil and .time #1

@CodeLenny

Description

@CodeLenny

void TestResponse.time(String handler, [Integer poll=10], Function<Boolean> test)
Takes a test function, and times how long it takes until the function returns a truthy value. Polls test every poll ms, defaulting to 10ms. Outputs the time as an integer via TestResponse.emit under the handler given.

Promise TestResponse.delayUntil([Array<Anything> args [, Integer poll=10], ] Function<Boolean> test)
Returns a promise that resolves after test returns a truthy value. Polls test every poll ms, defaulting to 10ms. Values passed as args are returned in the promise, as an array.

Example usage:

require ["jquery", "MyModule", "TestResponse"], ($, MyModule, TestResponse) ->
  MyModule.writeToDivLater "#output", "Blah Blah"
  TestResponse.time "time-to-output", -> $("#output").text() is "Blah Blah"
  TestResponse
    .delayUntil -> $("#output").text() is "Blah Blah"
    .then ->
      TestResponse.emit "output-length", $("#output").text().length
  • Implement
  • Document in guide

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions