Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create async gem sample #9

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@ concurrency:
cancel-in-progress: true

jobs:
test-async:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
container:
- 'ubuntu-20.04'
- 'alpine-3.17'
package_ruby_ver:
- '3.2.5'
container:
image: ghcr.io/tamatebako/tebako-${{ matrix.container }}:latest
steps:
- name: Install curl/procps
run: |
if [ -e "/etc/lsb-release" ]; then
apt-get -y update
apt-get -y install curl procps
elif [ -e "/etc/alpine-release" ]; then
apk --no-cache --upgrade add curl procps
fi

- name: Checkout sample
uses: actions/checkout@v4

- name: Package
run: tebako press -e binance.rb -o binance.tebako -r async -R ${{ matrix.package_ruby_ver }}

- name: Start packaged application
run: ./binance.tebako &

- name: Wait for the application to start and do some work
run: sleep 10

- name: End application
run: pkill -f binance.tebako

test-sinatra:
runs-on: ubuntu-latest
strategy:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,41 @@ concurrency:
cancel-in-progress: true

jobs:
test-async:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ macos-13, macos-14 ]
steps:
- name: Select XCode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 15.0.1

- name: Brew install
run: |
brew install bison flex binutils libffi double-conversion boost jemalloc fmt glog gnu-sed bash zlib ncurses
echo "$(brew --prefix bison)/bin" >> $GITHUB_PATH

- name: Install gem
run: gem install tebako

- name: Checkout sample
uses: actions/checkout@v4

- name: Package
run: tebako press -e binance.rb -o binance.tebako -r async

- name: Start packaged application
run: ./async.tebako &

- name: Wait for app to start and do some work
run: sleep 10

- name: End application
run: pkill -f async.tebako

test-sinatra:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
7 changes: 7 additions & 0 deletions async/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "async"
gem "async-http"
gem "async-websocket"
21 changes: 21 additions & 0 deletions async/binance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

require "async"
require "async/http"
require "async/websocket"

URL = "wss://stream.binance.com:9443/ws/btcusdt@bookTicker"

Async do |task|
endpoint = Async::HTTP::Endpoint.parse(URL, alpn_protocols: Async::HTTP::Protocol::HTTP11.names)

Async::WebSocket::Client.connect(endpoint) do |connection|
while message = connection.read
$stdout.puts message.parse
end
end
end
Loading