promise.cr v1.0.0

A Promise Implementation in Crystal

Promise.cr Build Status GitHub release Crystal Docs

A Promise Implementation in Crystal.

Installation

Add promise to the shard.yml file as a dependency.

# shard.yml
dependencies:
  promise:
    github: jwaldrip/promise.cr
    tag: {desired_tag}

Usage

require "promise"
require "http/client"
require "json"

def read_body(response : HTTP::Client::Response) : String
  response.body
end

request = Promise(HTTP::Client::Response | JSON::Any).execute do |resolve|
  HTTP::Client.get "https://httpbin.org/user-agent"
end

puts "do something else...."

request.then do |response|
  JSON.parse(read_body(response as HTTP::Client::Response))
end.catch do |ex|
  puts "caught!"
  puts ex.message
end.then do |json_hash|
  puts json_hash
end.await

Documentation

You can generate docs using crystal doc on your local machine, or visit: https://jwaldrip.github.com/promise-cr to view the current version's documentation.

Contributing

See CONTRIBUTING

Repository

promise.cr

Owner
Statistic
  • 32
  • 1
  • 1
  • 0
  • 0
  • about 4 years ago
  • July 28, 2016
License

MIT License

Links
Synced at

Tue, 23 Apr 2024 12:15:37 GMT

Languages