diff --git a/types/rethinkdb/index.d.ts b/types/rethinkdb/index.d.ts index c2dbf4b49b..6b4e3d0345 100644 --- a/types/rethinkdb/index.d.ts +++ b/types/rethinkdb/index.d.ts @@ -117,6 +117,17 @@ declare module "rethinkdb" { ssl?: TLSConnectionOptions; } + type waitFor = 'ready_for_outdated_reads' | 'ready_for_reads' | 'ready_for_writes'; + + interface WaitOptions { + waitFor?: waitFor; + timeout?: number; + } + + interface WaitResult { + ready: number; + } + interface NoReplyWait { noreplyWait: boolean; } @@ -143,6 +154,7 @@ declare module "rethinkdb" { tableDrop(name: string): Operation; tableList(): Operation; table(name: string, options?: GetTableOptions): Table; + wait(WaitOptions?): WaitResult; } interface TableOptions { @@ -233,6 +245,7 @@ declare module "rethinkdb" { get(key: string): Sequence; // primary key getAll(key: string, index?: Index): Sequence; // without index defaults to primary key getAll(...keys: string[]): Sequence; + wait(WaitOptions?): WaitResult; } interface Sequence extends Operation, Writeable { diff --git a/types/rethinkdb/rethinkdb-tests.ts b/types/rethinkdb/rethinkdb-tests.ts index 644ea58516..411a306d7c 100644 --- a/types/rethinkdb/rethinkdb-tests.ts +++ b/types/rethinkdb/rethinkdb-tests.ts @@ -22,7 +22,7 @@ r.connect({ host: "localhost", port: 28015 }, function(err: Error, conn: r.Conne testDb.tableCreate("users").run(conn, function(err, stuff) { const users = testDb.table("users"); - + users.wait({waitFor: 'ready_for_reads'}); users.insert({ name: "bob" }).run(conn, function() { }); @@ -55,6 +55,7 @@ r.connect({ host: "localhost", port: 28015 }).then(function(conn: r.Connection) console.log("HI", conn); const testDb = r.db("test"); + testDb.wait({timeout: 1}); r.table("players").hasFields("games_won").run(conn).then(cursorCallback); r.table("players").hasFields({ "games_won": { "championships": true } }).run(conn).then(cursorCallback); diff --git a/types/rethinkdb/tsconfig.json b/types/rethinkdb/tsconfig.json index 02a4846f80..4e794abe0d 100644 --- a/types/rethinkdb/tsconfig.json +++ b/types/rethinkdb/tsconfig.json @@ -19,4 +19,4 @@ "index.d.ts", "rethinkdb-tests.ts" ] -} \ No newline at end of file +}