Skip to content

Commit

Permalink
docs: README 中的错误示例
Browse files Browse the repository at this point in the history
用 asyncio 的形式改写
  • Loading branch information
Laisky committed Aug 2, 2016
1 parent 77858d5 commit 33fffcc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -60,7 +60,7 @@ target/
site

# commitizen
package.json
# package.json
node_modules

# venv
Expand Down
31 changes: 14 additions & 17 deletions README.md
Expand Up @@ -52,28 +52,26 @@ $ python -m ramjet [--debug=true]
### 异步

```py
import random
import asyncio

from ramjet.engines import process_executor, thread_executor, ioloop


def bind_task():
# 将任务添加进事件循环中
ioloop.add_future(async_task(), callback)


@tornado.gen.coroutine
def async_task():
yield tornado.gen.sleep(3)
yield async_child_task()
asyncio.ensure_future(async_task())


@tornado.gen.coroutine
def async_child_task():
yield tornado.gen.sleep(1)
print('child task ok!')
async def async_task():
await asyncio.sleep(3)
for i in range(10):
asyncio.ensure_future(async_child_task(i))


def callback(future):
print('ok')
async def async_child_task(n):
await asyncio.sleep(random.random())
print('child task {} ok!'.format(n))

```

Expand Down Expand Up @@ -104,14 +102,13 @@ from ramjet.engines import process_executor, thread_executor, ioloop
def bind_task():
now = ioloop.time()
run_at = now + 3600
ioloop.call_at(run_at, task, your_auguments)
delay = 3600
ioloop.call_later(delay, task, your_auguments)
def task(*args, **kw):
# 可以在 task 内设置下一次执行的时间
# ioloop.run_at(run_at, task, *args, **kw)
# ioloop.call_later(delay, task, *args, **kw)
```

## Versions
Expand Down
26 changes: 26 additions & 0 deletions package.json
@@ -0,0 +1,26 @@
{
"name": "ramjet",
"version": "1.0.0",
"description": "Ramjet ===",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git01.dds.com:ops/ramjet.git"
},
"author": "",
"license": "ISC",
"devDependencies": {
"cz-conventional-changelog": "^1.1.6"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

0 comments on commit 33fffcc

Please sign in to comment.