This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| await Person.findMany(p => p.age > 40); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ChiselEntity } from "@chiselstrike/api" | |
| export class Person extends ChiselEntity { | |
| name: string; | |
| age: number; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const usersWithPosts = await prisma.user.findMany({ | |
| orderBy: [ | |
| { | |
| role: 'desc', | |
| }, | |
| { | |
| name: 'desc', | |
| }, | |
| ], | |
| include: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Entity, Column, PrimaryGeneratedColumn } from "typeorm" | |
| @Entity() | |
| export class Photo { | |
| @PrimaryGeneratedColumn() | |
| id: number | |
| @Column({ | |
| length: 100, | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn scoped_task_unsound() { | |
| let le = LocalExecutor::default(); | |
| le.run(async { | |
| { | |
| let msg = &mut "hello"; | |
| let scoped = ScopedTask::local(async { | |
| eprintln!("write to invalid address"); | |
| *msg = "oh no"; | |
| }); | |
| std::mem::forget(scoped); // drop() doesn't run, so the task survives. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async fn some_async_function() { | |
| let shared = Rc::new(Cell::new(0)); | |
| let s = shared.clone(); | |
| let x = Task::local(async move { | |
| do_async_work(s).await; // used a Clone of shared state | |
| }); // <== task starts executing here | |
| do_more_work(shared); // <== may be still background executing here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{rc::Rc, time::Instant}; | |
| struct Foo { | |
| val: usize, | |
| } | |
| impl Foo { | |
| fn new(val: usize) -> Self { | |
| Foo { val } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let keep_running = Rc::new(Cell::new(true)); | |
| let kr = keep_running.clone(); // there are now two objects pointing to the same place | |
| // the ownership of this copy is passed to the task. | |
| let background_printer = Task::local(async move { | |
| while kr.get() { | |
| sleep(Duration::from_millis(100)).await; | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn spawn<F, T>(f: F) -> JoinHandle<T> | |
| where | |
| F: FnOnce() -> T, | |
| F: Send + 'static, | |
| T: Send + 'static, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub async fn get_buffer_aligned<'_>( | |
| &'_ mut self, | |
| len: u64 | |
| ) -> Result<ReadResult> |