more correct syntax and AI instructions
This commit is contained in:
@@ -12,7 +12,7 @@ Requestors are functions that encapsulate asynchronous work. They provide a stru
|
||||
A requestor is a function with this signature:
|
||||
|
||||
```javascript
|
||||
function my_requestor(callback, value) {
|
||||
var my_requestor = function(callback, value) {
|
||||
// Do async work, then call callback with result
|
||||
// Return a cancel function
|
||||
}
|
||||
@@ -29,13 +29,13 @@ The cancel function, when called, should abort the in-progress work.
|
||||
## Writing a Requestor
|
||||
|
||||
```javascript
|
||||
function fetch_data(callback, url) {
|
||||
var fetch_data = function(callback, url) {
|
||||
$contact(function(connection) {
|
||||
$send(connection, {get: url}, function(response) {
|
||||
callback(response)
|
||||
})
|
||||
}, {host: url, port: 80})
|
||||
return function cancel() {
|
||||
return function() {
|
||||
// clean up if needed
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ function fetch_data(callback, url) {
|
||||
A requestor that always succeeds immediately:
|
||||
|
||||
```javascript
|
||||
function constant(callback, value) {
|
||||
var constant = function(callback, value) {
|
||||
callback(42)
|
||||
}
|
||||
```
|
||||
@@ -52,7 +52,7 @@ function constant(callback, value) {
|
||||
A requestor that always fails:
|
||||
|
||||
```javascript
|
||||
function broken(callback, value) {
|
||||
var broken = function(callback, value) {
|
||||
callback(null, "something went wrong")
|
||||
}
|
||||
```
|
||||
@@ -74,9 +74,9 @@ var pipeline = sequence([
|
||||
|
||||
pipeline(function(profile, reason) {
|
||||
if (reason) {
|
||||
log.error(reason)
|
||||
print(reason)
|
||||
} else {
|
||||
log.console(profile.name)
|
||||
print(profile.name)
|
||||
}
|
||||
}, user_id)
|
||||
```
|
||||
@@ -133,7 +133,7 @@ var resilient = fallback([
|
||||
|
||||
resilient(function(data, reason) {
|
||||
if (reason) {
|
||||
log.error("all sources failed")
|
||||
print("all sources failed")
|
||||
}
|
||||
}, key)
|
||||
```
|
||||
@@ -157,7 +157,7 @@ If the requestor does not complete within the time limit, it is cancelled and th
|
||||
Requestors are particularly useful with actor messaging. Since `$send` is callback-based, it fits naturally:
|
||||
|
||||
```javascript
|
||||
function ask_worker(callback, task) {
|
||||
var ask_worker = function(callback, task) {
|
||||
$send(worker, task, function(reply) {
|
||||
callback(reply)
|
||||
})
|
||||
@@ -170,7 +170,7 @@ var pipeline = sequence([
|
||||
])
|
||||
|
||||
pipeline(function(stored) {
|
||||
log.console("done")
|
||||
print("done")
|
||||
$stop()
|
||||
}, {type: "compute", data: [1, 2, 3]})
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user