Skip to content
Open
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
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ Some tips:
- Always use `@deprecated` when applicable.
- Always use `@raise` when applicable.
- Always provide a `@see` tag pointing to MDN for more information when available.
- Format code samples in doc comments via `./cli/rescript-tools.js format-codeblocks <path-to-rescript-file>`

See [Ocamldoc documentation](http://caml.inria.fr/pub/docs/manual-ocaml/ocamldoc.html#sec333) for more details.

Expand Down Expand Up @@ -389,6 +390,7 @@ Adding a new entry there requires re-running the analysis tests. Follow these st
(If a `make` command fails, consider using the [DevContainer](#b-devcontainer).)

Finally, add a line to [CHANGELOG.md](CHANGELOG.md), using the `#### :nail_care: Polish` section.

## Code structure

The highlevel architecture is illustrated as below:
Expand Down
5 changes: 5 additions & 0 deletions packages/@rescript/runtime/Stdlib_Promise.res
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ external any: array<t<'a>> => t<'a> = "any"
external done: promise<'a> => unit = "%ignore"

external ignore: promise<'a> => unit = "%ignore"

let sleep = ms =>
make((resolve, _) => {
let _ = Stdlib_Global.setTimeout(resolve, ms)
})
15 changes: 15 additions & 0 deletions packages/@rescript/runtime/Stdlib_Promise.resi
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,18 @@ external done: promise<'a> => unit = "%ignore"
without having to store or process it further.
*/
external ignore: promise<'a> => unit = "%ignore"

/**
`sleep(ms)` creates a promise that resolves after `ms` milliseconds.

## Examples

```rescript
Promise.sleep(1000)
->Promise.thenResolve(() => {
Console.log("1 second has passed")
})
->Promise.ignore
```
*/
let sleep: int => promise<unit>
7 changes: 7 additions & 0 deletions packages/@rescript/runtime/lib/es6/Stdlib_Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ function $$catch(promise, callback) {
return promise.catch(err => callback(Primitive_exceptions.internalToException(err)));
}

function sleep(ms) {
return new Promise((resolve, param) => {
setTimeout(resolve, ms);
});
}

export {
$$catch,
sleep,
}
/* No side effect */
7 changes: 7 additions & 0 deletions packages/@rescript/runtime/lib/js/Stdlib_Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ function $$catch(promise, callback) {
return promise.catch(err => callback(Primitive_exceptions.internalToException(err)));
}

function sleep(ms) {
return new Promise((resolve, param) => {
setTimeout(resolve, ms);
});
}

exports.$$catch = $$catch;
exports.sleep = sleep;
/* No side effect */
Loading