☁ file.AsyncWrite - because THEY wont do it!!!!!! and its in RUST

Overview

gm_async_write

Simple module that adds file.AsyncWrite and file.AsyncAppend to Garry's Mod.

These functions are mostly based off file.AsyncRead and have similar arguments and usage.

These will probably not be 1:1 with a native GLua implementation (if we ever get one...), so do be aware that migrating from this to a native implementation may be a breaking change.

Installation

  1. Download the module that corresponds to your Garry's Mod server's branch and operating system.

    • If your server is Linux and running the main (default) branch, you need gmsv_async_write_linux.dll
    • If your server is Windows and running the main (default) branch, you need gmsv_async_write_win32.dll
    • If your server is Linux and running the x86-64 branch, you need gmsv_async_write_linux64.dll
    • If your server is Windows and running the x86-64 branch, you need gmsv_async_write_win64.dll
  2. Install it to garrysmod/lua/bin/ (if the folder does not exist, create it)

You're done!

Usage

See file.AsyncRead and FSASYNC

require("async_write")

local status = file.AsyncWrite("hello.txt", "Asynchronous write!", function(path, status)
	if status == FSASYNC_OK then
		print("OK!")
	elseif status == FSASYNC_ERR_FILEOPEN then
		print("Failed to open hello.txt")
	elseif status == FSASYNC_ERR_FAILURE then
		print("Failed to write to hello.txt")
	end
end)
print("Queued task, status: " .. status)

local status = file.AsyncAppend("hello.txt", "Asynchronous append! Who will win?", function(path, status)
	if status == FSASYNC_OK then
		print("OK!")
	elseif status == FSASYNC_ERR_FILEOPEN then
		print("Failed to open hello.txt")
	elseif status == FSASYNC_ERR_FAILURE then
		print("Failed to write to hello.txt")
	end
end)
print("Queued task, status: " .. status)
You might also like...
Sōzu HTTP reverse proxy, configurable at runtime, fast and safe, built in Rust. It is awesome! Ping us on gitter to know more

Sōzu · Sōzu is a lightweight, fast, always-up reverse proxy server. Why use Sōzu? Hot configurable: Sozu can receive configuration changes at runtime

A html document syntax and operation library written in Rust, use APIs similar to jQuery.

Visdom A server-side html document syntax and operation library written in Rust, it uses apis similar to jQuery, left off the parts thoes only worked

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

A rust web framework with safety and speed in mind.

darpi A web api framework with speed and safety in mind. One of the big goals is to catch all errors at compile time, if possible. The framework uses

Thruster - An fast and intuitive rust web framework

A fast, middleware based, web framework written in Rust

A full-featured and easy-to-use web framework with the Rust programming language.

Poem Framework A program is like a poem, you cannot write a poem without writing it. --- Dijkstra A full-featured and easy-to-use web framework with t

Seed is a Rust front-end framework for creating fast and reliable web apps with an Elm-like architecture.
Seed is a Rust front-end framework for creating fast and reliable web apps with an Elm-like architecture.

Seed is a Rust front-end framework for creating fast and reliable web apps with an Elm-like architecture.

example of a full stack web app (backend and frontend) wrtiten in Rust

rust-fullstack-example An example of creating a full stack web application (backend and frontend) using Rust. Backend Go to ./backend and start the se

A Rust GraphQL system with full support for subscriptions and authentication that works out of the box.

Diana is a GraphQL system for Rust that's designed to work as simply as possible out of the box, without sacrificing configuration ability.

Comments
  • `file.AsyncWrite/file.AsyncAppend` can cause a crash when a dedicated server is shutdown

    `file.AsyncWrite/file.AsyncAppend` can cause a crash when a dedicated server is shutdown

    Since a few days, or even weeks, I noticed that my dedicated development server was no longer shutting down properly. When I checked the logs, I saw that the server was crashing regularly with this error:

    thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: SendError(Job { raw_path: "github/test.json", path: "garrysmod/data/github/test.json", data: [123, 10, 9, 34, 115, 116, 114, 105, 110, 103, 49, 34, 58, 32, 116, 114, 117, 101, 44, 10, 9, 34, 115, 116, 114, 105, 110, 103, 50, 34, 58, 32, 102, 97, 108, 115, 101, 10, 125], callback: None, append: false, result: None })', src/worker.rs:38:25
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    fatal runtime error: Rust panics must be rethrown
    Aborted
    Add "-debug" to the ./srcds_run command line to generate a debug.log to help with solving this problem
    jeu. 10 févr. 2022 18:31:33 CET: Server restart in 10 seconds
    

    Other times, the server shuts down correctly and shows the following lines:

    L 02/11/2022 - 07:00:03: [Florian&Co] @ FAdmin: Server succesfully shut down.
    SoundEmitter:  removing map sound overrides [86 to remove, 0 to restore]
    Shutting down gm_async_write worker thread...
    L 02/11/2022 - 07:00:04: server_message: "quit"
    Could not find steamerrorreporter binary. Any minidumps will be uploaded in-processL02/11/2022 - 07:00:05: Log file closed.
    L 02/11/2022 - 07:00:05: server_message: "restart"
    ven. 11 févr. 2022 07:00:05 CET: Server Quit
    

    After some investigation, I retrieved the only script using your module and tried to reproduce the crash reliably. Here is the relevant code:

    require("async_write")
    
    local tbl = {
        ["string1"] = true,
        ["string2"] = false
    }
    
    file.CreateDir("github")
    
    hook.Add("ShutDown", "GitHub", function()
        file.AsyncWrite("github/test.json", util.TableToJSON(tbl, true))
        -- OR
        file.AsyncAppend("github/test.json", util.TableToJSON(tbl, true))
    end)
    

    Unfortunately these steps do not allow this issue to be reproduced all the time but it seems to appear very regularly (especially when the file is already present and it wants to rewrite the content). I did these tests in Sandbox gamemode without any addon to not falsify the results, moreover I had no other C++ modules than the latest version of your module.

    Here are the information of the dedicated server (running under Debian 11):

    Protocol version 24
    Exe version 2021.12.15 (garrysmod)
    Exe build: 16:38:55 Jan 27 2022 (8482) (4000)
    GMod version 2022.02.02, branch: unknown
    Linux 32bit Dedicated Server
    

    I don't have the chance at the moment to test this issue on the Windows version but I assume it occurs in other versions too. If you need more information, I am actively monitoring the repository 👍

    opened by FlorianLeChat 1
Owner
William
aka Billy
William
A brief implementation of a simple hello world program in rust since they said it couldn't be done.

rust-hello-world A brief blazingly fast ?? implementation of a simple hello world program in rust since they said it couldn't be done. ?? fast ?? Also

Enoki 2 Apr 16, 2022
Proxies all incoming connections to a minecraft server of your choosing, while also logging all ping and login requests to a json file and discord webhook.

minecraft-honeypot Proxies all incoming connections to a minecraft server of your choosing, while also logging all ping and login requests to a json f

Cleo 19 Jan 4, 2023
Rust Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.

Rust Embed Rust Custom Derive Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev. Y

Peter 1k Jan 5, 2023
Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation texts.

Rust I18n Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation te

Longbridge 73 Dec 27, 2022
Rustypaste is a minimal file upload/pastebin service.

Rustypaste is a minimal file upload/pastebin service.

Orhun Parmaksız 169 Jan 1, 2023
Magnesium-Oxide (MGO) a secure file uploader with support for ShareX.

A blazingly fast, ShareX uploader coded in Rust (using actix web) which utilizes AES-256-GCM-SIV to securely store uploaded content.

Magnesium 26 Nov 25, 2022
A simple authentication flow using Rust and Actix-web, with a PostgreSQL database and a sveltekit frontend.

Rust-auth-example This repository aims to represent a simple authentication flow using Rust and Actix-web, with a PostgreSQL database and a sveltekit

Kival Mahadew 4 Feb 19, 2023
A Google-like web search engine that provides the user with the most relevant websites in accordance to his/her query, using crawled and indexed textual data and PageRank.

Mini Google Course project for the Architecture of Computer Systems course. Overview: Architecture: We are working on multiple components of the web c

Max 11 Aug 10, 2022
Ergonomic and modular web framework built with Tokio, Tower, and Hyper

axum axum is a web application framework that focuses on ergonomics and modularity. More information about this crate can be found in the crate docume

Tokio 7.9k Dec 31, 2022
A secure and efficient gateway for interacting with OpenAI's API, featuring load balancing, user request handling without individual API keys, and global access control.

OpenAI Hub OpenAI Hub is a comprehensive and robust tool designed to streamline and enhance your interaction with OpenAI's API. It features an innovat

Akase Cho 30 Jun 16, 2023