Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
creadone committed Feb 26, 2021
1 parent 828ed95 commit 090490a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cocoon

Helper for wrap third-party API calls
Wrapper for IO such as third-party API calls to prevent sudden blow up the main program.

## Installation

Expand Down Expand Up @@ -30,10 +30,14 @@ channel = cocoon.wrap do
end
if resp = channel.receive
if resp.is_a?(Response) && resp.success?
pp JSON.parse(resp.body)
if resp.is_a?(Response)
if resp.success?
pp Array(Hash(String, JSON::Any)).from_json(resp.body)
else
Log.warn{ HTTP::Status.new(resp.status_code).description }
end
elsif resp.is_a?(Exception)
# log it and raise resp
Log.warn exception: resp, &.emit("Hi dear! I missed you.")
end
end
```
Expand Down
11 changes: 8 additions & 3 deletions example/base.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "log"
require "json"
require "../src/cocoon"
require "http/client"
Expand All @@ -11,9 +12,13 @@ channel = cocoon.wrap do
end

if resp = channel.receive
if resp.is_a?(Response) && resp.success?
pp JSON.parse(resp.body)
if resp.is_a?(Response)
if resp.success?
pp Array(Hash(String, JSON::Any)).from_json(resp.body)
else
Log.warn{ HTTP::Status.new(resp.status_code).description }
end
elsif resp.is_a?(Exception)
# log it and raise resp
Log.warn exception: resp, &.emit("Hi dear! I missed you.")
end
end
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: cocoon
version: 0.1.0
version: 0.1.1

authors:
- Sergey Fedorov <[email protected]>

description: |
Helper for wrap third-party API calls
Wrapper for IO such as third-party API calls to prevent sudden blow up the main program.
crystal: 0.36.1

Expand Down
11 changes: 3 additions & 8 deletions src/cocoon.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "http/client"

module Cocoon
VERSION = `shards version`

Expand All @@ -13,17 +11,14 @@ module Cocoon
def wrap(&block : -> T) forall T
spawn(name: "executor") do
@result.send block.call
rescue ex
@result.send ex
rescue ex
@result.send ex
end

Fiber.yield

spawn(name: "receiver") do
select
when data = @result.receive
@output.send data
end
@output.send @result.receive
end
@output
end
Expand Down

0 comments on commit 090490a

Please sign in to comment.