Skip to content

Commit

Permalink
Removing section on Custom Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
scalvert authored May 14, 2019
1 parent 5ad28af commit 26d8fef
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,80 +55,6 @@ export default class Friendz extends Component {
}
```

#### Custom Tokens

The `beginAsync` method also can receive a custom token, if you need to specifically define a token to represent your async operation. _Note_ - due to the nature of
async operations, it's difficult to determine which order the `endAsync` calls will run. If you are making multiple `beginAsync`/`endAsync` calls wiithin a single
class or function, _you need to ensure the uniqueness of each async operation by ensuring the uniqueness of the tokens you provide_.

The following code _will not_ guarantee uniqueness, as the two `endAsync` calls _may_ be called in succession:

```js
import Component from '@ember/component';
import { buildWaiter } from 'ember-test-waiters';

let waiter = buildWaiter('friend-waiter');

export default class Friendz extends Component {
didInsertElement() {
let token = waiter.beginAsync(this);

someAsyncWork().then(() => {
waiter.endAsync(this);
});
}

action: {
someAction() {
let token = waiter.beginAsync(this);

someOtherAsync()
.then(() => {
//... some work
})
.finally(() => {
waiter.endAsync(this);
});
}
}
}
```

The following code _will_ guarantee uniqueness, as the two `endAsync` calls _may_ be called in succession, but have unique tokens:

```js
import Component from '@ember/component';
import { buildWaiter } from 'ember-test-waiters';

let waiter = buildWaiter('friend-waiter');

export default class Friendz extends Component {
didInsertElement() {
let token = 'fist async';
waiter.beginAsync(token); // if a token is provided, `beginAsync` wil simply return it

someAsyncWork().then(() => {
waiter.endAsync(token);
});
}

action: {
someAction() {
let token = 'second async';
waiter.beginAsync(token);

someOtherAsync()
.then(() => {
//... some work
})
.finally(() => {
waiter.endAsync(token);
});
}
}
}
```

### waitForPromise function

This addon also provides a `waitForPromise` function, which can be used to wrap a promise to register it with the test waiter system. _Note_: the
Expand Down

0 comments on commit 26d8fef

Please sign in to comment.